Looping Macro

J

Jase

I have recorded a macro that selects a certain range then pastes into a
certain range then scrolls down about 50 cells and does the same thing. Is
there a way to loop this instead of always selecting particular ranges?

example of macro....

Range("S23:U23").Select
Application.CutCopyMode = False
Selection.Copy
Range("S63").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("S73:U73").Select
Application.CutCopyMode = False
Selection.Copy
Range("S123").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
 
M

Mike H

Possibly

Sub Stitution()
For x = 23 To 73 Step 50
Range("S" & x & ":U" & x).Select
Application.CutCopyMode = False
Selection.Copy
Range("S" & x + 50).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Next
End Sub

Mike
 
J

Jase

This does not work. It is only copying the starting range scrolling down and
pasting it and then copying the same data and scrolling another 50 cells and
pasting it again. I need it to grab range S23:U23 copy scroll down like 10
rows paste scroll down another 50 from the initial S23:U23. So we r now at
S73 copy this date scroll down 10 rows from here and paste that data. Then go
dow to S123 copy that data scroll down 10 and paste and so on and so on.
 
S

Sandy Mann

Try something like:

Sub Test()
p = 10 '<- Change to the number of Rows
'you want to go down before pasting

Application.ScreenUpdating = False

For r = 23 To 323 Step 50
Range("S" & r & ":U" & r).Copy
Range("S" & r + p).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next r

Application.ScreenUpdating = True
End Sub


--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings

(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk
 
J

Jase

This is exactly what I need. Thank you.

Sandy Mann said:
Try something like:

Sub Test()
p = 10 '<- Change to the number of Rows
'you want to go down before pasting

Application.ScreenUpdating = False

For r = 23 To 323 Step 50
Range("S" & r & ":U" & r).Copy
Range("S" & r + p).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Next r

Application.ScreenUpdating = True
End Sub


--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings

(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk
 
S

Sandy Mann

Glad to help. Thanks for the feedback.

--

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings

(e-mail address removed)
Replace @mailinator.com with @tiscali.co.uk
 

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

Top