PDA

View Full Version : Sleeper: Using loop Macros



blackcat
06-01-2006, 07:35 AM
:help Hi everyone, i am a newbie. I have one question regarding the loop Macro. I am very very new to macro so i think its easier to record them instead. I want to record a macro so that it can copy a row with data then paste the data into the next row and keep doing that until i tell it to stop. In case i cant do it with recording , can anyone help me with writing the code?
Thanks a lot :ipray:

OBP
06-01-2006, 08:37 AM
Unfortunately "Looping" can't be recorded in a macro, you have to write (or copy/paste) it in. It would normally involve either a set number of loops or until a certain condition is met. You could have a message box asking if you want to continue after each paste.
Can you post your Workbook on here with a description of what you want to paste and where to paste it?

mdmackillop
06-01-2006, 01:10 PM
Hi Blackcat,
Welcome to VBAX
There are different approaches to this. Here's a couple to start with, which ask for user input.
Regards
MD



Sub DoCopy()
Dim Rw As Long
Rw = ActiveCell.Row
ActiveCell.EntireRow.Copy
For i = 1 To InputBox("Times to copy")
Range("A" & Rw + i).PasteSpecial
Next
Application.CutCopyMode = False
End Sub

and


Sub DoFill()
Range(ActiveCell.EntireRow, ActiveCell.Offset(InputBox("Times to copy"))_
.EntireRow).FillDown
End Sub