Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Loop stan Excel Discussion (Misc queries) 1 October 22nd 09 04:38 PM
Help with using a Macro Loop Mark Costello[_2_] Excel Discussion (Misc queries) 5 October 19th 07 02:01 PM
Loop to run macro each row PST Excel Discussion (Misc queries) 1 May 17th 07 06:36 AM
loop a macro jnjwilliams94 Excel Discussion (Misc queries) 4 August 26th 06 01:52 PM
macro loop Helen Excel Discussion (Misc queries) 7 January 12th 05 02:42 PM


All times are GMT +1. The time now is 11:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"