for loop in excel macro

L

Li Chen

Hi all,

Here is an off -Ruby topic. Recently I need to do a lot of work in Excel
with repeated work. And macro might be some help.
I wonder how I can loop some ranges of cells using a for loop in
Excel.

Thanks,

Li


For i =0 To 4 Step 1
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range("A1:D1,A2:D2")

MsgBox i
Next


###############################
after each step the following line should change as follows:

Range("A1:D1,A2:D2")

Range("A1:D1,A3:D3")

Range("A1:D1,A4:D4")

.....
 
R

Rodrigo Bermejo

Li said:
Hi all,

Here is an off -Ruby topic. Recently I need to do a lot of work in Excel
with repeated work. And macro might be some help.
I wonder how I can loop some ranges of cells using a for loop in
Excel.

Thanks,

Li


For i =0 To 4 Step 1
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range("A1:D1,A2:D2")

MsgBox i
Next


###############################
after each step the following line should change as follows:

Range("A1:D1,A2:D2")

Range("A1:D1,A3:D3")

Range("A1:D1,A4:D4")

.....

You can perform this task using Ruby.
You can find plenty of info about right here:

http://rubyonwindows.blogspot.com/search/label/excel


Then the required loop can be implemented in the ruby way you are used
to.
 
L

Li Chen

Rodrigo said:
You can perform this task using Ruby.
You can find plenty of info about right here:

http://rubyonwindows.blogspot.com/search/label/excel


Then the required loop can be implemented in the ruby way you are used
to.


Hi Rodrigo,


Thanks for the link. I might refer it if I use a lot of Excel
automation. But I need a quick method for my project immediately. I
just get some help from VBA group in Yahoo:

Range("A1:D1,A" & i + 2 & ":D" & i + 2)


Li
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top