+ Reply to Thread
Results 1 to 15 of 15

Macro to copy data to applicable sheet

  1. #1
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Macro to copy data to applicable sheet

    I have branch names in Col A and sheet names for each unique name in Col A


    I would like code to copy the data to each sheet based on the name in Col A. for eg if the sheet is KLM-1
    , and KLM-1 is in Col A, then all the items for KLM-1 is to be copied from col A to Col F , including the header


    I have shown what the data is after manually copying the data


    It would be appreciated if someone could provide me with code to do this
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to copy data to applicable sheet


    It depends if working only with already existing worksheets or for all elements of column A
    whatever if some worksheet exists or not ? (if not to be created on the run …)

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Macro to copy data to applicable sheet

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)


    It would be appreciated if someone could provide me with code to do this:Go to the Commercial Services section of this site http://www.excelforum.com/commercial-services/
    And read the FAQ on how to solicit paid help.
    Ben Van Johnson

  4. #4
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Macro to copy data to applicable sheet

    Thanks for the reply Marc


    The sheets already exist. The macro must match the sheet name to the item in Col A for eg match sheet KLM-1 to Col A and copy all the items KLM-1 in Col A as well as the items in the columns to the right of KLM-1 that are applicable to KLM-1

  5. #5
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Macro to copy data to applicable sheet

    Hi Ben


    Thanks for pointing this oiut to me and my apologies for transgressing the rules

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    Like any beginner can operate manually just using a filter so as a beginner starter :

    PHP Code: 
    Sub Demo1()
       
    Dim Rg As RangeVW&
            
    Application.ScreenUpdating False
       Set Rg 
    Worksheets(1).UsedRange
            V 
    Rg.Range("A1:A2").Value
        
    For 2 To Worksheets.Count
            With Worksheets
    (W)
                 
    V(21) = .Name
                
    .UsedRange.Clear
                
    .[K1:K2].Value V
                 Rg
    .AdvancedFilter xlFilterCopy, .[K1:K2], .[A1]
                .[
    K1:K2].Clear
            End With
        Next
            Set Rg 
    Nothing
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Macro to copy data to applicable sheet

    Thanks for the help

  8. #8
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Macro to copy data to applicable sheet

    Hi Marc


    You kindly helped me recently with code to Copy data from Sheet 1 where the Name in Col A matches the sheet name


    I need the code amended , so that sheet2 ("purchases") is also copied to the sheets where the names in Col A matches the sheet names from Sheet3 onwards, but after after the last row containing data after the mfirst macro is run to copy the data from sheet1


    Your assistance in this regard is most appreciated

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool


    Try this !

    PHP Code: 
    Sub Demo1b()
        
    Dim Rg(1 To 2) As RangeVW&
            
    Application.ScreenUpdating False
        Set Rg
    (1) = Worksheets(1).UsedRange
        Set Rg
    (2) = Worksheets(2).UsedRange
            V 
    Rg(1).Range("A1:A2").Value
        
    For 3 To Worksheets.Count
            With Worksheets
    (W)
                 
    V(21) = .Name
                
    .UsedRange.Clear
                
    .[K1:K2].Value V
                 Rg
    (1).AdvancedFilter xlFilterCopy, .[K1:K2], .[A1]
                 
    Rg(2).AdvancedFilter xlFilterInPlace, .[K1:K2]
                 
    Rg(2).Offset(1).Copy .Cells(.UsedRange.Rows.Count 11)
                .[
    K1:K2].Clear
            End With
        Next
            
    If Rg(2).Parent.FilterMode Then Rg(2).Parent.ShowAllData
            Erase Rg
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  10. #10
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Macro to copy data to applicable sheet

    Thanks Mark. Code works perfectly

  11. #11
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Macro to copy data to applicable sheet

    Hi Marc


    I have tested your code on another workbook, where the headings are in row 11 and the data stsrts from row 12.

    I need sheet "Customer profile" to be copied to the relevant sheet based on the branch name in Col A. for Eg awhere BR! in is Col A, then all the data for BR1 (all columns) to be copied to sheet BR1 (BR1 to only contain data for branch BR1) BR2 for BR data etc


    Once this is copied, I need the data in sheet purchases for each branch to be copied to the relevant sheet. This must be copied after the last row containing data on these sheets

    As can seen for the atached workfile, that the data is not being copied corectly into the relevant sheet. for Eg sheet BR1 containds ddata for branch BR2, BR3,BR4 & BR8. It must only contain data for BR1





    Your assistance in amending your code is most appreciated
    Attached Files Attached Files
    Last edited by flupsie; 06-23-2018 at 12:27 AM.

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Last but not least ?!


    Better than asking for any variation, wait before creating any thread
    until your need is fixed and once you understand it …
    As copying cells is at beginner level, you must understand the code in order to be able to maintain it,
    as all is yet in VBA inner help …

    So just using Excel inner features according to your last attachment the last beginner starter :

    PHP Code: 
    Sub Demo1c()
      Const 
    "A11"
        
    Dim Rg(2) As RangeVW&
        
    Set Rg(1) = Sheet1.Range(F).CurrentRegion
        Set Rg
    (2) = Sheet22.Range(F).CurrentRegion
            Application
    .ScreenUpdating False
            V 
    Rg(1).Range("A1:A2").Value
        
    For 5 To Worksheets.Count
            With Worksheets
    (W)
                 
    Set Rg(0) = .[K1:K2]
                 
    V(21) = .Name
                
    .UsedRange.Clear
                 Rg
    (0).Value V
                 Rg
    (1).AdvancedFilter xlFilterCopyRg(0), .Range(F)
                 
    Rg(2).AdvancedFilter xlFilterInPlaceRg(0)
                 
    Rg(2).Offset(1).Copy .Cells(.UsedRange.Rows.Count 11)
                 
    Rg(0).Clear
            End With
        Next
            
    If Sheet22.FilterMode Then Sheet22.ShowAllData
            Erase Rg
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 06-23-2018 at 08:37 AM. Reason: optimization …

  13. #13
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Last but not least ?!

    Thanks for the help Marc. Code works 100%

    Please explain the following items in your code

    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to copy data to applicable sheet


    Previous post edited as a codeline was missing …

    Constant F for first cell,
    Sheet22 is the CodeName of a source data worksheet as you can easily check on VBE side with the Projects window …

  15. #15
    Spammer
    Join Date
    08-20-2012
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    221

    Re: Macro to copy data to applicable sheet

    Thanks for the explanation

+ 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] Master tab serial number list parsed out to applicable cells in applicable worksheets
    By kiwimtnbkr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2017, 10:57 AM
  2. [SOLVED] Copy data in column A to every applicable row in group
    By cindywylie in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-14-2014, 06:50 AM
  3. [SOLVED] Macro to copy data from a master sheet to separate sheet as per date using a macro
    By tmaster81 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2014, 08:05 AM
  4. [SOLVED] VBA Create Sheets & Copy Applicable Data
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2014, 07:39 AM
  5. [SOLVED] Macro to Copy Data from one Sheet A to Sheet B based on value in cell on sheet A
    By scass in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2012, 07:21 PM
  6. copy applicable data from one sheet to another
    By Onesie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2009, 04:51 AM
  7. autocopy applicable data from one sheet to another in excel
    By Onesie in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-12-2009, 05:24 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