티스토리 뷰

Programming

Excel - VBA 특정 배경색 바꾸기

파란크리스마스 2016. 1. 29. 14:44
728x90

출처 : 엑셀(Excel) 개발도구 탭 추가하기 (리본메뉴에 개발도구 탭 표시)

Sub Hello()

    Dim Sht As Worksheet
    Dim iRow As Integer
    
    For Each Sht In Worksheets
        'Sht.Cells.WrapText = True
        If Sht.Index >= 3 Then
            'MsgBox (Sht.Name)
            Sht.Select
            MsgBox (ActiveSheet.Name)
            For iRow = 7 To ActiveSheet.UsedRange.Rows.Count
            
                If Sht.Cells(iRow, 1) = "마지막행" Then
                    Exit For
                End If
                
                ' 가운데 정렬
                With Sht.Cells(iRow, 6)
                    .HorizontalAlignment = xlCenter
                    .VerticalAlignment = xlCenter
                End With
                With Sht.Cells(iRow, 7)
                    .HorizontalAlignment = xlCenter
                    .VerticalAlignment = xlCenter
                End With
                
                Sht.Cells(iRow, 2).Select
                
                
                ' 노락색 인경우 = 6
                If ActiveCell.Interior.ColorIndex = 6 Then
                    ' 회색으로 변경 = 15
                    Sht.Cells(iRow, 1).Interior.ColorIndex = 15
                    Sht.Cells(iRow, 2).Interior.ColorIndex = 15
                    Sht.Cells(iRow, 3).Interior.ColorIndex = 15
                    Sht.Cells(iRow, 4).Interior.ColorIndex = 15
                    Sht.Cells(iRow, 5).Interior.ColorIndex = 15
                    Sht.Cells(iRow, 6).Interior.ColorIndex = 15
                    Sht.Cells(iRow, 7).Interior.ColorIndex = 15
                    Sht.Cells(iRow, 8).Interior.ColorIndex = 15
                End If
                'MsgBox (Sht.Cells(iRow, 1))
            Next iRow
        End If
    Next Sht
End Sub



댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함