Do Loop

bahllr

Board Regular
Joined
May 7, 2009
Messages
62
I am trying to get a Do Loop for the following problem:

If a cell (in range (B5:B10) = "1" then

select the 4 cells to the right of that cell (with the "1")
and highlight them.

next cell

I have part of this but can't seem to get it to work....could someone please help me?

Sub test()

Range("b5").Activate
If ActiveCell.Value = 1 Then
Range(ActiveCell, ActiveCell.Offset(0, 4)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
ActiveCell.Offset(1, 0).Select

End If
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I'd use a For..Next

Sub test()

Range("b5").Activate

For Counter = 1 to 10
If ActiveCell.Value = 1 Then
Range(ActiveCell, ActiveCell.Offset(0, 4)).Select
With Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
end if
ActiveCell.Offset(1, 0).Select
Next Counter

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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