Consulting

Results 1 to 8 of 8

Thread: Copy and Paste loop

  1. #1
    VBAX Regular
    Joined
    Jul 2019
    Posts
    36
    Location

    Copy and Paste loop

    I'm trying to do a relatively simple copy and paste.

    I am Copying 3 cell values, and also assigning a cell value to a string variable,
    once all done go to Output sheet and paste strDer variable value to B2 and value of smatch to B3, B4, B5
    Then loop to next row.

    I need help with the pasting bit.



    Dim smatch as range
    Dim strDer  as string
    
    strDer = smatch.Offset(0, -1).Value
    copval=   ActiveCell.Resize(, 3).Copy

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test()
        Dim r As Range
        Dim m
        Dim n As Long
    
        n = 2
        For Each r In Rows("11:20")
            m = Application.Match("testing", r, 0)
            If IsNumeric(m) Then
                Cells(n, "B").Resize(, 3).Value = r.Cells(m).Resize(, 3).Value
                n = n + 1
            End If
        Next
    
    End Sub

  3. #3
    VBAX Regular
    Joined
    Jul 2019
    Posts
    36
    Location
    my lngMyrow is dim as long. I'm trying to use like this
    Range(lngMyRow).Resize(, 3).Value
    but getting error
    and I need to assign to a variable so i can paste later.

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Range("E" & lngMyRow).Resize(, 3).Value
    
    
    Cells(lngMyRow, "E").Resize(, 3).Value

  5. #5
    VBAX Regular
    Joined
    Jul 2019
    Posts
    36
    Location
    "E"? I dont know which column it will be

  6. #6
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    >"E"

    It's just an example


  7. #7
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Could you give me sample data?

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Quote Originally Posted by Pamella View Post
    I'm trying to do a relatively simple copy and paste.

    I am Copying 3 cell values, and also assigning a cell value to a string variable,
    once all done go to Output sheet and paste strDer variable value to B2 and value of smatch to B3, B4, B5
    Then loop to next row.

    I need help with the pasting bit.
    Q: Do you want to keep on making the copies a long column in B, i.e. B2:B5 for first copy, B6:B9 for next, etc.?

    Q: Where does smatch get a value

    Q: How is the input data structured; A1:Z26 on Sheet1? Is Row 1 headers?

    Sample workbook with the before and after would be helpful
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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