Consulting

Results 1 to 4 of 4

Thread: Solved: Copy Xrows from WrkBk to New WrkBk

  1. #1
    VBAX Regular mike31z's Avatar
    Joined
    Apr 2005
    Location
    Highland, Wisconsin
    Posts
    98
    Location

    Solved: Copy Xrows from WrkBk to New WrkBk

    I have this little code that I modified and can not get it to work.
    Source File Name= Event1.xls with one Tab named Event1 (This was created by importing a txt file in csv format.

    The destinagation file is E1Mgmt.xls exsisting tab "import" There are other tabs but I would like the data being copied on the existing "import" tab.

    I get the code to work but it creates new worksheet named "Import (1) and so on" I need it to overwrite the exisiting import worksheet.

    [VBA]Sub copyEvt()
    '
    ' copyEvt Macro
    ' Macro recorded 7/26/2011 by Mike
    '
    Windows("Event1.xls").Activate
    Sheets("Event1").Select
    Sheets("import").Copy Before:=Workbooks("E1Mgmt.xls").Sheets(1)
    Cells.Select
    Selection.Interior.ColorIndex = xlNone
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown
    Range("B3").Select

    End Sub[/VBA]

    Thanks for looking

    Mike in Wisconsin
    Last edited by mike31z; 04-08-2012 at 01:40 PM.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.
    assuming both workbooks are open; try:

    [VBA]
    Sub CopyRngToAnotherWB()

    Dim ws1 As Worksheet, ws2 As Worksheet

    Set ws1 = Workbooks("Event1.xls").Sheets("Event1")
    Set ws2 = Workbooks("E1Mgmt.xls").Sheets("import")

    ws1.UsedRange.Copy ws2.Range("A1")

    with ws2
    .Cells.Interior.ColorIndex = xlNone
    .Rows(1).Insert
    End With

    End Sub
    [/VBA]

    you can call this sub from a third workbook.
    Last edited by mancubus; 04-08-2012 at 03:21 PM.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular mike31z's Avatar
    Joined
    Apr 2005
    Location
    Highland, Wisconsin
    Posts
    98
    Location
    Thanks mancubus
    That works just just fine. It looks easy to modify for other worksheet copy and paste functions.
    Thanks for the quick response.

    Mike in Wiscsonsin

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    You're wellcome.
    Sure..

    and thanks for marking the thread solved.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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