VBA Colour

adurham22926192

New Member
Joined
Dec 17, 2019
Messages
49
Office Version
  1. 2019
Platform
  1. Windows
Hi all,

i have a selected range and i need a button linked to a macro to change the cell and font colour of lets say A10:I10 but the next time i click the button i need it to change the cell and font colour of A9:I9 and so on until it gets to the top.

Pls helpppp
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Perhaps something like this:

VBA Code:
Sub ColorRows()
Dim x As Long
For x = 10 To 1 Step -1
    If Cells(x, 1).Interior.Color <> vbYellow Then
        Cells(x, 1).Resize(, 9).Interior.Color = vbYellow
        Exit For
    End If
Next
End Sub
 
Upvote 0
Another possible interpretation (also only dealing with cell color here)

VBA Code:
Sub Color_Rows()
  Dim oldrow As Long, newrow As Long
  
  Application.FindFormat.Clear
  Application.FindFormat.Interior.Color = vbYellow
  On Error Resume Next
  oldrow = Range("A1:A10").Find(What:="", SearchFormat:=True).Row
  On Error GoTo 0
  If oldrow < 2 Then
    oldrow = 1
    newrow = 10
  Else
    newrow = oldrow - 1
  End If
  Cells(oldrow, 1).Resize(, 9).Interior.Color = xlNone
  Cells(newrow, 1).Resize(, 9).Interior.Color = vbYellow
  Application.FindFormat.Clear
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,676
Messages
6,126,165
Members
449,295
Latest member
DSBerry

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