+ Reply to Thread
Results 1 to 3 of 3

Need macro for Copying data

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2012
    Location
    chennai
    MS-Off Ver
    Excel 2003
    Posts
    34

    Thumbs up Need macro for Copying data

    Hi Champs,


    i have a excel master data file saved at c: in my computer.

    I used to get xls attachment in my outlook everyday.

    i need a macro to copy the content in the attached excel file to the excel master data file (without disturbing already saved contents in master data file).


    Your help is deeply appreciated.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,716

    Re: Need macro for Copying data

    Look at adapting this code to your specific situation

    Sub CopyOpenItems() 
       ' 
       ' CopyOpenItems Macro 
       ' Copy open items to sheet. 
       ' 
       ' Keyboard Shortcut: Ctrl+Shift+O 
       ' 
       Dim wbTarget            As Workbook 'workbook where the data is to be pasted 
       Dim wbThis              As Workbook 'workbook from where the data is to copied 
       Dim strName             As String   'name of the source sheet/ target workbook 
        
       'set to the current active workbook (the source book) 
       Set wbThis = ActiveWorkbook 
        
       'get the active sheetname of the book 
       strName = ActiveSheet.Name 
        
       'open a workbook that has same name as the sheet name 
       Set wbTarget = Workbooks.Open("C:\filepath\" & strName & ".xlsx") 
        
       'select cell A1 on the target book 
       wbTarget.Range("A1").Select 
        
       'clear existing values form target book 
       wbTarget.Range("A1:M51").ClearContents 
    
       'activate the source book 
       wbThis.Activate 
        
       'clear any thing on clipboard to maximize available memory 
       Application.CutCopyMode = False 
        
       'copy the range from source book 
       wbThis.Range("A12:M62").Copy 
        
       'paste the data on the target book 
       wbTarget.Range("A1").PasteSpecial 
        
       'clear any thing on clipboard to maximize available memory 
       Application.CutCopyMode = False 
        
       'save the target book 
       wbTarget.Save 
        
       'close the workbook 
       wbTarget.Close 
    
       'activate the source book again 
       wbThis.Activate 
        
       'clear memory 
       Set wbTarget = Nothing 
       Set wbThis = Nothing 
        
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    09-11-2013
    Location
    Huntsville, AL
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Need macro for Copying data

    Range("A1").End(xlDown).Offset(1).Select
    This will move the Activecell to the bottom of the range assuming there is data in every row cell in column A where you already have data. If not, there is some extra steps to make.

    This will dynamically select everything except the headers from the from workbook.
    Range("A1").CurrentRegion.Select
    This will copy all the data but the header:
    Range("A1").CurrentRegion.Select
    Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1, Selection.Columns.Count).Copy
    This will Copy the code in a dynamic region with the first row of data.
    Range("A1").CurrentRegion.Copy
    Thanks,

    Gregg
    Last edited by greggpetersen75; 09-20-2013 at 04:19 PM.

+ 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. Need help with macro copying data
    By GribbletheMunchkin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2012, 06:40 AM
  2. Replies: 1
    Last Post: 04-02-2011, 06:39 AM
  3. Copying data into a new row - macro
    By dextras in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-12-2009, 06:29 AM
  4. Copying Data Via A Macro
    By lj123 in forum Excel General
    Replies: 2
    Last Post: 11-21-2008, 07:23 AM
  5. copying data using a macro
    By stuart_@James in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2008, 01:05 PM

Tags for this Thread

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