Alternate Row Colors in Range

前端 未结 8 1626
轻奢々
轻奢々 2020-12-09 13:13

I\'ve come up with the following to alternate row colors within a specified range:

Sub AlternateRowColors()
Dim lastRow as Long

lastRow = Range(\"A1\").End(         


        
相关标签:
8条回答
  • 2020-12-09 13:37

    My Solution

    A subroutine to assign to a button or some code

    Public Sub Band_Goals()
        'Just pass the start and end rows
        'You will have to update the function to select the
        'the correct columns
    
        BandRows_Invisble 12, 144
    
    End Sub
    

    The Function

    Private Sub BandRows_Invisble(StartRow As Integer, EndRow As Integer)
    
        Dim i As Long, nothidden As Boolean
    
    
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
    
        Range("A" & StartRow & ":K" & EndRow).Interior.ColorIndex = xlNone
    
        For i = StartRow To EndRow
            If Not Rows(i).Hidden Then
                nothidden = nothidden + 1
                If Not nothidden Then
                        'Download this app to help with color picking
                        'http://www.iconico.com/download.aspx?app=ColorPic
                        Range("A" & i & ":K" & i).Interior.Color = RGB(196, 189, 151)
    
                End If
            End If
        Next i
    
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
    
    End Sub
    
    0 讨论(0)
  • 2020-12-09 13:37

    In my Excel 2010, there is an option to format as table, where you can also select a range and headers. No need for scripting.

    0 讨论(0)
提交回复
热议问题