Select Range, Change Each Row Color, Macro

teksp0rt

New Member
Joined
Feb 6, 2008
Messages
33
I am fairly new to writing macros in VBA.

What I would like to do is select a range of rows and column with my mouse...

  1. For example, I would select the range B20:Z50
  2. Then, I would like to hit a macro button..
  3. Every other row - the color of the row will change to light grey hex: #F2F2F2

Anyone have advice on how to get me started?
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
This might help.
VBA Code:
Sub HighlightRows()
Dim rng As Range
Dim rngRow As Range

    Set rng = Selection
    
    For Each rngRow In rng.Rows
        If rngRow.Row Mod 2 = 1 Then
            rngRow.Interior.Color = &HF2F2F2
        Else
            rngRow.Interior.Color = xlNone
        End If
    Next rngRow
    
End Sub
 
Upvote 0
How about
VBA Code:
Sub teksport()
   Dim Cl As Range
   
   For Each Cl In Selection.Rows
      If Cl.Row Mod 2 = 0 Then Cl.Interior.Color = RGB(242, 242, 242)
   Next Cl
End Sub
 
Upvote 0
Try this code:
VBA Code:
Sub MyCFMacro()

    With Selection
        .FormatConditions.Add Type:=xlExpression, Formula1:="=MOD(ROW(),2)=1"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -0.14996795556505
        End With
        .FormatConditions(1).StopIfTrue = False
    End With
    
End Sub
Change the color to your liking (you can get the code you want ny recording yourself applying it, and then taking that number and replacing the one in my code above).
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top