Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to loop through cells in macro
I have a basic macro (compliments of macro builder) but
want to repeat the same steps x times. My macro is cutting, pasting, and deleting rows in a prospect database. For each contact I have 4 rows of data and want to consolidate to 1 row, and then delete the three blank rows. Then move onto the next contact record. How do I loop the steps or use the Dim counter to cycle through 1000 rows? I'd appreciate any good resources for a beginner. Thanks in advance. Andrew |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to loop through cells in macro
Assuming your data is in column A, rows 1 to 1000
Sub ConsolidateData() Dim i As Long Dim rng As Range For i = 1 To 1000 Step 4 Cells(i, 2).Value = Cells(i + 1, 1).Value Cells(i, 3).Value = Cells(i + 2, 1).Value Cells(i, 4).Value = Cells(i + 3, 1).Value If rng Is Nothing Then Set rng = Cells(i, 1).Offset(1, 0).Resize(3, 1) Else Set rng = Union(rng, Cells(i, 1).Offset(1, 0).Resize(3, 1)) End If Next rng.EntireRow.Delete End Sub -- Regards, Tom Ogilvy "Andrew" wrote in message ... I have a basic macro (compliments of macro builder) but want to repeat the same steps x times. My macro is cutting, pasting, and deleting rows in a prospect database. For each contact I have 4 rows of data and want to consolidate to 1 row, and then delete the three blank rows. Then move onto the next contact record. How do I loop the steps or use the Dim counter to cycle through 1000 rows? I'd appreciate any good resources for a beginner. Thanks in advance. Andrew |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro Loop | Excel Discussion (Misc queries) | |||
Help with using a Macro Loop | Excel Discussion (Misc queries) | |||
Loop to run macro each row | Excel Discussion (Misc queries) | |||
loop a macro | Excel Discussion (Misc queries) | |||
macro loop | Excel Discussion (Misc queries) |