Consulting

Results 1 to 6 of 6

Thread: VBA Copy and Paste HELP

  1. #1
    VBAX Regular
    Joined
    Jul 2009
    Posts
    37
    Location

    VBA Copy and Paste HELP

    Hey Everybody,

    I am having a problem with copying and pasting the correct range. Please take a look at the attached file. When I run the code, VBA copies range A10:B29, instead of A10:B27, which is what's specified in the code. Can you please point out the problem.

    Thanks,
    Dimitriy

  2. #2
    VBAX Regular
    Joined
    Sep 2008
    Posts
    39
    Location
    Sorry, I posted a possible solution but didn't work the 2nd time I ran it, Try Abdul's solution below. I'll keep seeing what the issue is.

  3. #3
    Sheets(ActiveSheet.Range("B1").Value).Select
    Range("A10:B10").End(xlDown).Resize(, -1).Select
    Selection.Copy
    Sheets("Main Table").Select
    Range("A4").Select
    ActiveSheet.Paste
    Post Questions - Get Answers

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Avoid Select where possible
    [VBA]
    Sub TEST()
    Sheets(ActiveSheet.Range("B1").Value).Select
    If Range("A28").End(xlUp).Row > 9 Then
    Range("A10", Range("A28").End(xlUp)).Resize(, 5).Copy _
    Sheets("Main Table").Range("A4")
    'or
    Range("A10", Range("A28").End(xlUp)).Resize(, 5).Copy _
    Sheets("Main Table").Cells(Rows.Count, 1).End(xlUp).Offset(1)
    End If
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Jul 2009
    Posts
    37
    Location
    Thanks, guys, for your help!

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Remember to mark your threads Solved using the Thread Tools dropdown.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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