Forum Discussion

Aless1275's avatar
Aless1275
Copper Contributor
Oct 09, 2021
Solved

Create a MACRO to select specific rows through an iteration and colour them (Excel VBA)

Hi, i'm having troubles to do the create an iteration with a for cycle that enables me to select specific row.. So, i have a table with 2 columns, as you can see in the file attached (A with the dat...
  • HansVogelaar's avatar
    Oct 09, 2021

    Aless1275 

    You could use Conditional Formatting:

     

    Select A2:B8761. A2 should be the active cell in the selection.

    On the Home tab of the ribbon, click Conditional Formatting > New Rule...
    Select 'Use a formula to determine which cells to format'.
    Enter the formula

    =$B2=1

    Click Format...
    Activate the Fill tab.
    Select a highlight color.
    Click OK twice.

     

    If you prefer VBA:

    Sub color_Rows_Days_test()
        Dim r As Long
        Dim m As Long
        Application.ScreenUpdating = False
        m = Range("B1").End(xlDown).Row
        For r = 2 To m Step 24
            With Range("A" & r).Resize(1, 2).Interior
                .ThemeColor = xlThemeColorAccent2
                .TintAndShade = 0.799981688894314
            End With
        Next r
        Application.ScreenUpdating = True
    End Sub

     

     

Resources