PDA

View Full Version : Loop excel Macro to repeat as long as there is data in the colum



dkassin
02-28-2012, 01:35 PM
Have a macro that I need to loop as long as there is data in the columns. The macro works for six columns. I have another macro that runs prior to this one which adds columns to the sheet and then fills in the required data. I need macro to run and work for all data as more is added.

So basically I need to know how to write the code so that I could put it around my already written macro to loop it every six columns with a condition that it stops once there is no data in the upcoming column.

Any help would be greatly appreciated.
Thanks

CatDaddy
02-28-2012, 01:42 PM
Dim cell as range
For each cell in range("A1:A" & Range("A65000").end(xlup).row)
...do stuff to cell...
next cell

dkassin
02-28-2012, 01:49 PM
For Each cell in Range("A:A1)& Range ("650000").end(xlup).row)

Shows up as a red error and it says Syntax

Why is that?

CatDaddy
02-28-2012, 02:03 PM
you have an extra closed parantheses


For Each cell in Range("A:A1)& Range ("A650000").end(xlup).row)

should be:

For Each cell in Range("A:A1" & Range ("A650000").end(xlup).row)

dkassin
02-28-2012, 02:10 PM
I got another error that said Method 'Range' of object "_Global'failed this time.

CatDaddy
02-28-2012, 02:17 PM
that was my fault, should be:
For Each cell In Range("A1:A" & Range ("A650000").end(xlup).row)

dkassin
02-28-2012, 02:33 PM
This code did not work correctly.

I basically need a macro to copy itself and work for all of the columns with are to the right of the first six columns. So the macro imputs data every 6 columns I need it to input data if there are six more column of data in the sheet until there is no more data.

If that make it any more clear

CatDaddy
02-28-2012, 02:38 PM
sample workbook?