View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Loop macro in selected range

If you want to loop use this

Sub Test()
Dim smallrng As Range

For Each smallrng In Range("A1:A4,C7,D9,A11:G11").Areas
With smallrng
.Interior.ColorIndex = 3
End With
Next smallrng

End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Ron de Bruin" wrote in message ...
Use it like this

Range("A1:A4,C7,D9,A11:G11").Interior.ColorIndex = 3


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Sjaakve" wrote in message ...
Hi,

I am new to VBA. I dug up a macro on the web somewhere. It does what
is has to do, but only for the active cell. When I select multiple
cells the macro only works on one cell. I would like it to loop, and
do all the cells.

I tried recording a macro for a selection, but only got this:

Range("A1:A4,C7,D9,A11:G11").Select
Range("A11").Activate
Application.Run "Macro1"

and that several times


This is what I would like:

I've selected A1:A4,C7,D9,A11:H11

The excisting macro is named Macro1 and gives the cell a red color.

If I run the macro now only A11 turns red.

I would like a macro that repeats Macro1 for the active selection.

Can anybody tell me how this is done?

Thanx,

Sjaak