Hi,
Please read the forum rules and in particular the ruke about wrapping code lines inside CODE tags. I have done it for you on this occasion as this is your first post.
Original post......
Hello,
I want to copy rows from one sheet to another sheet, but this number of rows is different every time. Also the first row to select is not always the same. I want to use an input box in which the user can enter a number. This number needs to be used to determine which rows have to be copied according to this formula:
first row to copy = 2*Number + 8
last row to copy = 4*Number + 9
I created this macro but it doesn't work. What am I doing wrong?
Thanks a lot.Code:Sub inputbox() Sheets("Sheet1").Activate Dim Number As Integer Set Number = Application.inputbox( _ prompt:="Enter number", Type:=1) Sheets("Sheet1").Select Rows("8+2*Number:9+2*Number").Select Selection.Copy Sheets("Sheet2").Select Range("A1").Select ActiveSheet.Paste End Sub
Last edited by Richard Buttrey; 01-28-2010 at 06:27 AM. Reason: Missing Code tags
See code below
HTHCode:Sub Inputbox() Sheets("Sheet1").Activate Dim Number As Long, FirstRow As Long, LastRow As Long Number = Application.Inputbox(prompt:="Enter number", Type:=1) FirstRow = Number * 2 + 8 LastRow = Number * 4 + 9 Sheets("Sheet1").Range("A" & FirstRow & ":A" & LastRow).EntireRow.Copy Destination:=Sheets("sheet2").Range("A1") End Sub
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks