Forum Discussion

Vimal_Gaur's avatar
Vimal_Gaur
Brass Contributor
Jan 23, 2023
Solved

VBA Background color

VBA - Need shortcut key to change background color of ENTIRE row of active cell It should also change background color of ENTIRE rows of active / selected cells
  • OliverScheurich's avatar
    OliverScheurich
    Jan 24, 2023

    Vimal_Gaur 

    Sub colorseveralwows()
    
    Dim i As Long
    Dim bereich As Range
    Set bereich = Selection
    
    For i = bereich.Row To bereich.Row + bereich.Rows.Count - 1
     
    Rows(i).Interior.Color = vbBlue
     
    Next i
     
    End Sub

    You can run this code with the shortcut ctrl+B in the attached file. The macros colors rows 7, 8 and 9 blue if you select e.g. cells F7, F8 and F9.

Resources