Consulting

Results 1 to 6 of 6

Thread: Copy InputBox

  1. #1
    VBAX Regular
    Joined
    Nov 2004
    Location
    Richmond, IN
    Posts
    36
    Location

    Copy InputBox

    This code works when I put 1 in the InputBox but if I put 2 or 3 in it will stop at SRg = Range(Rg.Item(0), Rg.Item(i).Offset(0, 16)).Address.
    Thank you for your help.

    Sub PasteRowAX1T() 
    ' PasteRowAX1 Macro
    Application.ScreenUpdating = False
    Dim Rg As Range
    Dim SRg As String
    Dim LRg As String
    RowIns = InputBox("Enter number of rows required")
    For i = 1 To RowIns
    Set Rg = Selection
    SRg = Range(Rg.Item(0), Rg.Item(i).Offset(0, 16)).Address
    Range(SRg).Select
    LRg = Range(Rg.Item(0).Offset(1, 16), Rg.Item(i).Offset(0, 16)).Address
    Selection.Copy Destination:=Range(SRg & ":" & LRg)
    Cells(ActiveCell.Row, 1).Resize(1, 17).Copy _
    Destination:=Cells(ActiveCell.Row + 1, 1).Resize(RowIns, 1)
    Next i
    Cells(ActiveCell.Row + 2, 1).Select
    Set Rg = Nothing
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Looking briefly at it, that suggests to me that your selection is a single cell. so it doesn't have a 2nd or 3rd item to work on.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Nov 2004
    Location
    Richmond, IN
    Posts
    36
    Location
    xld - Thank you for your help.
    What the code does is copy down the line above it from Column A to Column Q.
    It copies down when I put 1 in the InputBox but not when I put in 2 or 3 ?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It doesn't work for me at all, with 1, 2 or 3.

    The reason is that you reference item(0), and there is no item(0).

    This worked, but n copies depending upon the input.


    Sub PasteRowAX1T()
         ' PasteRowAX1 Macro
        Application.ScreenUpdating = False
        Dim Rg As Range
        Dim SRg As String
        Dim LRg As String
    RowIns = InputBox("Enter number of rows required")
        For i = 1 To RowIns
            Set Rg = Selection
            SRg = Range(Rg.Item(1), Rg.Item(i).Offset(0, 16)).Address
            Range(SRg).Select
            LRg = Range(Rg.Item(1).Offset(1, 16), Rg.Item(i).Offset(0, 16)).Address
            Selection.Copy Destination:=Range(SRg & ":" & LRg)
    Cells(ActiveCell.Row, 1).Resize(1, 17).Copy _
            Destination:=Cells(ActiveCell.Row + 1, 1).Resize(RowIns, 1)
        Next i
    Cells(ActiveCell.Row + 2, 1).Select
        Set Rg = Nothing
    Application.ScreenUpdating = True
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Nov 2004
    Location
    Richmond, IN
    Posts
    36
    Location

    It Works

    xld - Thank you it works perfect.
    I just was not smart enough to figure that out about the 1 and 0.
    I have a lot of trouble understanding VBA.
    I learn more each time I have trouble and I receive help.
    Thank you very much for your help.

  6. #6
    Moderator VBAX Mentor sheeeng's Avatar
    Joined
    May 2005
    Location
    Kuala Lumpur
    Posts
    392
    Location
    xld, you are a great helper here...
    I learn from you too.
    thx.

Posting Permissions

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