Consulting

Results 1 to 8 of 8

Thread: Copy Paste sheet Range to another worksheet

  1. #1
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location

    Copy Paste sheet Range to another worksheet

    I was trying to copy a sheet range to another worksheet with the below code. It seems to work if there is more than 1 visible row to be copied but when its just only one visible row, it copy to the entire target range as duplicates.

    [VBA]
    Sub Create_Supplier()

    Dim RngSup As Range
    Dim FmlaSup As Range
    Set FmlaSup = ActiveSheet.Range("A10:bc505")
    Set RngSup = Sheets("Supplier_Distribution").Range("b10")
    Application.GoTo Reference:="Supplier_Clear"
    Selection.ClearContents

    FmlaSup.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    Sheets("Supplier_Distribution").Select
    Range("a1").Select
    End Sub

    [/VBA]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  2. #2
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Hi Jammer6_9

    Could you attach an example of your worksheet?
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  3. #3
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Hi, thanks for the reply. Let me see how can I get a sample sheet as the file is huge and sheets are link to each other.

    Quote Originally Posted by Sir Babydum GBE
    Hi Jammer6_9

    Could you attach an example of your worksheet?
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I don't see anything to limit the copying of less than the whole range specified.
    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
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by mdmackillop
    I don't see anything to limit the copying of less than the whole range specified.
    In my exploration, if the source range is autofiltered, only visible cells seem to be copied (xl2003).
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Hi, find attached sample file. Thanks a lot.
    Attached Files Attached Files
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    [vba]Sub Create_Supplier()
    Dim RngSup As Range
    Dim FmlaSup As Range

    Set FmlaSup = ActiveSheet.Range("A10:bc505")
    Set RngSup = Sheets("Supplier_Distribution").Range("b10")
    Range("Supplier_Clear").ClearContents
    Sheets("Supplier_Distribution").Select
    FmlaSup.Copy
    RngSup.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Range("a1").Select
    End Sub
    [/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    VBAX Mentor jammer6_9's Avatar
    Joined
    Apr 2007
    Location
    Saudi Arabia
    Posts
    318
    Location
    Thanks that works! Seems that I missed to put the source range that I have declared.

    Quote Originally Posted by p45cal
    try:
    [VBA]Sub Create_Supplier()
    Dim RngSup As Range
    Dim FmlaSup As Range

    Set FmlaSup = ActiveSheet.Range("A10:bc505")
    Set RngSup = Sheets("Supplier_Distribution").Range("b10")
    Range("Supplier_Clear").ClearContents
    FmlaSup.Copy
    RngSup.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("Supplier_Distribution").Select
    Range("a1").Select
    End Sub
    [/VBA]
    T-ogether
    E-veryone
    A-chieves
    M-ore


    One who asks a question is a fool for five minutes; one who does not ask a question remains a fool forever.

Posting Permissions

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