Consulting

Results 1 to 6 of 6

Thread: Copy values from another workbook

  1. #1

    Copy values from another workbook

    Hi,

    I want to copy values only from one workbook to another and some cells being copied are merged. I would like to copy only values to another workbook but end up with a error.
    I have used
    [vba]
    Dim wbSource as workbooks
    Dim wbDestination as workbooks

    wbSource.Worksheets("Sheetname").Usedrange.Copy wbDestination.Worksheets("SheetName").Range("A1").Paste xlPasteSpecial
    [/vba]
    Thanks

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    You are not assigning any objects. Is this your whole code?
    Also you have used workbooks instead of workbook (a collection instead of a single object).
    Are both workbooks open?
    Are you just trying to copy a single range?

    Basically let us know specifically what you need and we can likely help.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  3. #3
    HI Brian,

    I just whipped up the code of the top of my head how I did the copy worksheet from another book to another.

    But I have a issue when copying, when source sheet has merged cells and destination has exact duplicate sheet but when copying values using Paste special values causes error or anything but pasteAll but that gives me formulas.

    What is the correct way when copying from one sheet to another where both has merged cells

    Thanks

  4. #4
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    Can you post an example of your data and the spreadsheet you want the data to copy to. Are you looking to just copy a whole sheet to another workbook?
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  5. #5
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [VBA]Dim wbSource As workbook
    Dim wbDestination As workbook

    set wbSource = Workbooks("someworkbookname.xlsx")
    set wbDestination = Workbooks("someotherworkbookname.xlsx")

    wbSource.Worksheets("Sheetname").Usedrange.Copy destination:=wbDestination.Worksheets("SheetName").Range("A1")[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  6. #6
    Hi,

    I have actually set to import 2 worksheets
    What I have used is below

    [vba] 'Set Import Sheet1 WPS
    strPath = Worksheets("Data").Range("PATH_WPS")
    strFileName = Worksheets("Data").Range("WPS_GL1")
    strType = Worksheets("Data").Range("WPS_GL_EXT") ' for Macro enabled 2007 format

    'set sheet name to import
    sSheet1 = Worksheets("Data").Range("WPS_GL1").Value
    sSheet2 = Worksheets("Data").Range("WPS_GL2").Value


    'Get sheet names to import and copy to correct location
    Set wbSource = Workbooks.Open(Filename:=strPath & strFileName & strType, ReadOnly:=True)

    wbSource.Sheets(sSheet1).UsedRange.Copy
    wbCurrent.Sheets("WPS_GL1 WK1").Range("A1").PasteSpecial Paste:=xlPasteAll

    wbSource.Sheets(sSheet2).UsedRange.Copy
    wbCurrent.Sheets("WPS_GL2 WK2").Range("A1").PasteSpecial Paste:=xlPasteAll[/vba]

    This will import everything ok, but I only want values and no formula
    if I use xlPasteValues or anything but xlPasteall I get and error

    Thanks

Posting Permissions

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