Cell colors in VBA

Post Reply
wwj
Posts: 2497
Joined: 27 Jan 2007 08:16

Cell colors in VBA

Post by wwj »

Code: Select all


    ' step 1. Copy the list of wells into the output sheet.
    ' max number of obs locations.
    maxMWs = Sheets(inSht).Cells(Rows.Count, "I").End(xlUp).Row
    For j = 2 To maxMWs
        obsid = Sheets(inSht).Cells(j, "I")
        col = (j - 2) * 2 + 1
        
        Sheets(outSht).Cells(1, col) = obsid
        Sheets(outSht).Cells(1, col + 1) = ""
        Sheets(outSht).Cells(2, col) = "Date"
        Sheets(outSht).Cells(2, col + 1) = "GWL"
        
        If (j Mod 2) Then
            colorcode = 20
        Else
            colorcode = 40
        End If
        
        Sheets(outSht).Cells(1, col).Interior.ColorIndex = colorcode
        Sheets(outSht).Cells(1, col + 1).Interior.ColorIndex = colorcode
        Sheets(outSht).Cells(2, col).Interior.ColorIndex = colorcode
        Sheets(outSht).Cells(2, col + 1).Interior.ColorIndex = colorcode
        
    Next j

Post Reply