+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    01-24-2010
    Location
    brussels
    MS-Off Ver
    Excel 2007
    Posts
    9

    use input from user

    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?

    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
    Thanks a lot.
    Last edited by Richard Buttrey; 01-28-2010 at 06:27 AM. Reason: Missing Code tags

  2. #2
    Forum Moderator Richard Buttrey's Avatar
    Join Date
    02-15-2008
    Location
    Grappenhall, UK
    MS-Off Ver
    Excel for Windows & Mac - all versions.
    Posts
    5,826

    Re: use input from user

    See code below

    Code:
    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
    HTH
    Richard Buttrey

    If this was useful then please rate it appropriately.

    Click the small star icon at the bottom left of my post.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0