+ Reply to Thread
Results 1 to 6 of 6

Copy Data_But don't clear data already on sheet

  1. #1
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    OFFICE 365
    Posts
    187

    Copy Data_But don't clear data already on sheet

    Hi,

    I have the code below which works fine, But how can it be modified that it doesn't clear the data or names already in the template sheet.

    here is the code:

    Option Explicit

    Sub CopyOutput()
    Dim wb1 As Workbook, wb2 As Workbook
    Dim Ret1, Ret2

    Set wb1 = ActiveWorkbook

    '~~> Get the File
    Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
    , "Please select file")
    If Ret1 = False Then Exit Sub

    Set wb2 = Workbooks.Open(Ret1)
    wb2.Sheets(1).Cells.Copy wb1.Sheets(1).Cells
    wb2.Close SaveChanges:=False


    Set wb2 = Nothing
    Set wb1 = Nothing
    End Sub


    Thank you,

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,005

    Re: Copy Data_But don't clear data already on sheet

    In the absence of any sample files or knowledge of the structure of the data, best guess:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    OFFICE 365
    Posts
    187

    Re: Copy Data_But don't clear data already on sheet

    Hi,

    your suggestion works in a way that doesn't erase anything which is good but won't start copying from "A1" cell, attaching file always should past from cell "A1".

    Same format all the time so should always copy data starting from Cel "A1"




    Thank you,
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    OFFICE 365
    Posts
    187

    Re: Copy Data_But don't clear data already on sheet

    Hi,

    I think I figure it out,

    I changed this line from:

    Please Login or Register  to view this content.
    To this line:

    Please Login or Register  to view this content.
    After modifying it like that now Starting from cell "A1" and doesn't erased anything already in the template.
    If it is a better way to do it, please let me know.
    attaching a revised one.

    Thank you
    Attached Files Attached Files

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,005

    Re: Copy Data_But don't clear data already on sheet

    Pretty sure that's what the code is doing. It copies the used range from the source sheet after the used range of the target sheet (the active sheet with the button) in the target workbook (ThisWorkbook: the book running the code)

  6. #6
    Forum Contributor
    Join Date
    11-05-2012
    Location
    Canada
    MS-Off Ver
    OFFICE 365
    Posts
    187

    Re: Copy Data_But don't clear data already on sheet

    But target sheet from A1 is empty but code before I changed it was pasting it on row starting A125 down not from A1.

    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] copy last colum from sheet to second column in another sheet with clear others columns
    By tubrak in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2022, 05:27 AM
  2. VBA Code to copy sales data to different sheet and clear
    By akshay_401 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-15-2019, 08:00 AM
  3. [SOLVED] Multiple sheet copy paste with sheet clear
    By Rachel5694 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-15-2019, 01:21 PM
  4. Copy and clear data and print sheet VBA
    By rashidn73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-09-2016, 04:02 AM
  5. [SOLVED] Help with a macro to copy data to other sheet and clear cells
    By bazofio in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2014, 07:59 PM
  6. Replies: 1
    Last Post: 11-28-2013, 02:10 AM
  7. Macro to copy Dyanmic lists then copy sheet and clear the original data
    By twiggywales in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2012, 01:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1