Thread: Macro Loop
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Macro Loop

Patty, here is what the code currently does:

1. The ActiveCell object sets up a relative reference, which means that
wherever the cursor happens to be (which cell is active) is considered
Range("a1"). So if the cursor is on cell G15 the selected cells in this case
will be G15 through M15. Since his next command moves the cursor up 30 rows,
I assume that it had been placed lower on the worksheet by some code not
posted in this snippet.

2. If the intent is to copy the absolute cells $A$1:$G$1 and the cursor is
set anywhere above row 31 then the line ActiveCell.Offset(-30,0) will fail
because there will not be enough rows to accomplish the command.

3. Using the Range("A1") designation after ActiveCell.Offset( ) is not
necessary, the select will move the cursor and it will know where it is.

4. Disabling the CutCopyMode between copies is also unnecessary, each copy
command overrides the previous one so the disable command can be moved to the
end of all the copy processes.

5. I cleaned the code up a little as you can see below, but since you do
not provide information about the sheet layout and what criteria is being
used to select and copy the data, I am afraid I cannot help with the
For...Each...Next or even a Do...Loop.

"pattylb" wrote:

I'm trying to help someone with this looping this macro. Here's his code:

ActiveCell.Range("A1:G1").Select
Selection.Copy
ActiveCell.Offset(-30, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(24, -3).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveSheet.Next.Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

I'm a rather inexperienced programmer, but my thoughts were to wrap this
with a For...Next which I think I could figure out. But, I also think that
the macro will have to begin in a certain cell each time in order for his
offsets to work.

So, any help would be appreciated that starts this macro at E36 and loops it
like 5000 times.

Thanks very much.