Select an range of cells to perform task on each

Atholl

Active Member
Joined
May 19, 2002
Messages
436
Hi all,

I have a grid of numbers from C:10 to R:96. The numbers range from 0 to 5 and I have a piece of code "ConditionalDoc" which assigns a fill colour depending on the number in the cell. At present, I have code which selects each cell in the grid individually in turn and performs the fill colour code:

Range("C80").Select
ConditionalDoc
Range("C81").Select
ConditionalDoc
Range("C82").Select
ConditionalDoc
etc....

Is there a quicker way to select all of the cells and perform ConditionalDoc on each?

Atholl
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Well, first select you entire range then call the macro like this:
Code:
Range("C80:C82").Select 
ConditionalDoc

Then put a loop in your ConditionalDoc code that loops through each cell one at a time, i.e.
Code:
Dim cell as Range
For each cell in Selection
'   Your code here
Next cell
 
Upvote 0
Thanks for the reply!

This seems to be clashing with my ConditionalDoc code which looks a bit like this:

If Selection > 0 And Selection <= 1 Then
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

etc.

I think 'Selection' needs to be changed, but to what?
 
Upvote 0
Never mind, I got it!


If cell.Value > 0 And cell.Value <= 1 Then
With cell.Interior
.ColorIndex = 3
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

:)

Thanks again,


Atholl
 
Upvote 0

Forum statistics

Threads
1,215,149
Messages
6,123,311
Members
449,095
Latest member
Chestertim

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