+ Reply to Thread
Results 1 to 21 of 21

VBA code to copy raw data into summary table

  1. #1
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    VBA code to copy raw data into summary table

    Hi All,

    Could you please assist? I have a bit of excel knowledge but not VBA.

    We have a commission sheet of about 400+ rows of each employees commission calculations which are in various categories, such as connections, insurance sales, accessories etc. I want a button to be able to copy only specific values from the rows into a prelim "salary slip" that are in columns format to email to staff.
    We work on employee numbers.

    From this: (One row per employee)
    Emp No Accessory Qty Accessories com OMS Connections Connection Commission
    781 23 605.12 44 1 560.00

    To this: (One Summary table per employee)
    781 R
    Contract connections 0 -
    Warehouse Connections 0 -
    Accessory Sales 0 -


    Not sure if it makes sense. There are columns in between that don't need to be copied over.

    Basically, I want the program to take the raw data and if it matches that employee number, copy for example data from column I to Accessory Sales, copy value in column P to Contract connections, etc.

    Copy from Commission Sheet to Prelim Sheet.

    We have already set up Macros to email their prelims, but we copy and paste data manually at the moment for 400+ employees and it's too much work.

    Thank you in advance for the assistance.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Hi,

    So I did some research and found this code:

    Sub SearchForString()

    Dim LSearchRow As Integer
    Dim LCopyToRow As Integer

    On Error GoTo Err_Execute

    'Start search in row 2
    LSearchRow = 2

    'Start copying data to row 2 in Sheet2 (row counter variable)
    LCopyToRow = 2

    While Len(Range("A" & CStr(LSearchRow)).Value) > 0

    'If value in column C = "781", copy entire row to Sheet2
    If Range("C" & CStr(LSearchRow)).Value = "781" Then

    'Select row in Sheet17 to copy
    Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
    Selection.Copy

    'Paste row into Sheet18 in next row
    Sheets("Sheet18").Select
    Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
    ActiveSheet.Paste

    'Move counter to next row
    LCopyToRow = LCopyToRow + 1

    'Go back to Sheet1 to continue searching
    Sheets("Sheet17").Select

    End If

    LSearchRow = LSearchRow + 1

    Wend

    'Position on cell A3
    Application.CutCopyMode = False
    Range("A3").Select

    MsgBox "All matching data has been copied."

    Exit Sub

    Err_Execute:
    MsgBox "An error occurred."

    End Sub

    The problem is that I don't want to copy the entire row, just a certain value in a specific column.

    And when I change the employee number and run it again, it pastes over the first row.

    I am desperate for help

    If anyone can guide me, I would be appreciate it.

  3. #3
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: VBA code to copy raw data into summary table

    Hello April88 and Welcome to Excel Forum.
    I believe that you could accomplish what you want with formulas once the employee number has been entered.
    The formula for names of the consultants could be: =INDEX('Commission Calc'!$A2:$A4,MATCH(B1,'Commission Calc'!$B2:$B4,0))
    The other fields could be: =INDEX('Commission Calc'!$C2:$N4,MATCH(B1,'Commission Calc'!$B2:$B4,0),MATCH(A3,'Commission Calc'!$C1:$N1,0))
    Note that I only found one direct match for the name of the field, Warehouse Connections, so that and the consultant name are the only formulas placed in the attachment.
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  4. #4
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Hello JeteMc,

    Thank you very much for your reply - I really appreciate you taking the time to help me.

    What would you suggest - that we change the headers on the commission sheet?

    I really hoped there would be a quicker way to import the data. The problem is that the consultants move to various stores regularly, so we have to keep the sheet updated.

    Regards,
    April88

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: VBA code to copy raw data into summary table

    "What would you suggest - that we change the headers on the commission sheet?"

    I feel that changing the column headers on the commission sheet so that they match the row headers on the prelim sheet would be the easiest way.

    "I really hoped there would be a quicker way to import the data."

    If the headers match then the prelim sheet should instantly display the information that is on the commission sheet, assuming that we are being provided an accurate sample of the commission sheet.

    "The problem is that the consultants move to various stores regularly, so we have to keep the sheet updated."

    I believe that we need more information as to what happens to the data when a consultant moves to another store. As in is the data overwritten, is another row of data added to the commission sheet, or is this handled in another way?

    Let us know if you have any questions.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: VBA code to copy raw data into summary table

    Not really clear about which column from "Commission Calculations" correspond to which row in "Prelim", so adjust the line in Bold.
    If "Commission Calculations" workbook is open, you need to close it before you run the code.
    Please Login or Register  to view this content.
    Last edited by jindon; 10-14-2019 at 11:26 PM.

  7. #7
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Hello,

    Thank you very much - you have been such a big help Wish I could buy you coffee or something for your trouble.

    I have started changing the header names in the commission sheet and it works wonders.

    To answer your move question:
    Each store has its own tab: REDS, GROV, JAK, etc (the names don't matter) We copy paste the entire block of the consultant.
    For instance, if a consultant moves from REDS to GROV, we copy that persons block and paste in the GROV tab. I checked and the formula stays put, so that's not the problem.

    What you could maybe assist with, is the following:
    1. Each month has a new commission sheet - how will I keep the formulas updated when the new month starts?
    Ex. This month’s sheet name is Commission – September
    Next months’ is Commission – October
    But we use the same prelim sheet and just copy the data from the commission sheet.
    2. The first formula that we used is for the quantity of items sold; how do I copy the money value to the next column? The commission sheet format never changes.

    Sample attached.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Hi,

    I actually figured this one out: (2. The first formula that we used is for the quantity of items sold; how do I copy the money value to the next column? The commission sheet format never changes.)

    =INDEX('[Copy of Book1 B.xlsx]Sheet1'!$C$2:$AU$7,MATCH($B$1,'[Copy of Book1 B.xlsx]Sheet1'!$C$2:$C$7,0),MATCH(A2,'[Copy of Book1 B.xlsx]Sheet1'!$C$1:$AU$1,0)+1)

    Added the +1 to the formula



    April

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: VBA code to copy raw data into summary table

    If I understand request #1 correctly:
    First I would suggest that you put all of the commission information on the same sheet and in the same workbook as the prelim sheet. There are over one million rows on a sheet so a sheet can store years (14,563 years actually) of data for six employees. Even with many more employees a sheet could hold many years of data. If you do this then you could add another column for month and year (as I assume that you don't want your September 2019 data combined with the September 2020 data) to the commission information sheet. We could then modify the formulas on the prelim sheet to add that criteria.
    Second, if you feel that you have to keep the commission information on separate sheets but in the same workbook as the prelim sheet, we could use the INDIRECT function to identify from which sheet the data should be obtained.
    Last choice would be to keep the commission information in a separate workbook. That will require that you change the ...[Commission Calculations September 2019.xlsx]... to ...[Commission Calculations October 2019.xlsx]... each month, although you could use VBA, such as Jindon is recommending, to obtain the data.
    Let us know which option you want to use and/or if you have any questions.

  10. #10
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Hi Jindon,

    I must be honest that I have zero VBA knowledge, so I don't even know what the above code means *I feel embarrassed*

    I think that the formulas that JeteMC has given me has helped the most so far - but thank you for the effort!!!

    JeteMC - I could maybe try to paste over the old data in the commission sheet and File > Save As > New name for both. Do you think that would work?

    I feel really silly asking all these questions, but when I try to google these things, it's not much help.

    Is there a way that I could copy the formula to all 20 tabs at the same time without changing the references?

    April

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: VBA code to copy raw data into summary table

    This is to show how the code works as you posted the question in VBA forum.
    You will see a dialogue box after you click on the button to select the file to be imported, so select "Commission Calculations Sample.xlsx".
    As I mentioned in the previous post, not really sure the order of the output.
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: VBA code to copy raw data into summary table

    If I understand correctly you would like to put the prelim salary slip onto the same sheet as the commission table. If that is a correct understanding then yes the formulas could all have the same references.
    The attached file demonstrates how this would work.

  13. #13
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Jindon,

    This was exactly what I was looking for. We have about 5 workbooks with 15-20 sheets each with about 5-10 employees on each sheet. (400 plus employees in total)

    Column B is for QTY and column C is for the money value. How would I add the money value as well? And do it for more than 400 employees?

    Even if each sheet has its own click button - its better than copy and pasting all the data.

    April

  14. #14
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    JeteMC,

    I think I'm going to use the formulas that you helped with until I can build the code to do what Jindon helped with.

    You guys are truly amazing

    April

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: VBA code to copy raw data into summary table

    Quote Originally Posted by April88 View Post
    This was exactly what I was looking for. We have about 5 workbooks with 15-20 sheets each with about 5-10 employees on each sheet. (400 plus employees in total)

    Column B is for QTY and column C is for the money value. How would I add the money value as well? And do it for more than 400 employees?
    I don't understand the relation between those 5 workbooks with multiple sheets and the result.
    If you make up few dummy data with multiple worksheets and the result workbook, I will see if it can be done like the way I did or other way to accomplish the job.

  16. #16
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: VBA code to copy raw data into summary table

    Thank You for the feedback. I hope that you have a blessed day.

  17. #17
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Quote Originally Posted by jindon View Post
    I don't understand the relation between those 5 workbooks with multiple sheets and the result.
    If you make up few dummy data with multiple worksheets and the result workbook, I will see if it can be done like the way I did or other way to accomplish the job.
    We are a sales company. Each workbook is a Province, each province has 5-20 stores (worksheets) and each store has 5-10 employees (the prelim sheet).

    We have one commission sheet with all 400 + employees commission payouts and have to pull the data into the prelims and that little block we email to the sales people to check if they agree before we do payroll.

    We used to copy paste each persons data manually to their prelim block, but this takes too much time. Hence the reason I asked the forum for help to see if we can automate it.

    Hope that makes sense?

  18. #18
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Quote Originally Posted by April88 View Post
    We are a sales company. Each workbook is a Province, each province has 5-20 stores (worksheets) and each store has 5-10 employees (the prelim sheet).

    We have one commission sheet with all 400 + employees commission payouts and have to pull the data into the prelims and that little block we email to the sales people to check if they agree before we do payroll.

    We used to copy paste each persons data manually to their prelim block, but this takes too much time. Hence the reason I asked the forum for help to see if we can automate it.

    Hope that makes sense?

    Hi Jindon,

    Please see attached sample data. The workbooks must be kept separate, because we get a new commission sheet each month.

    There is also a word document attached that tells you which headers in the commission sheet link to the Prelim sheet.

    Thank you very much

    April
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    10-09-2019
    Location
    South Africa
    MS-Off Ver
    Office 365
    Posts
    11

    Re: VBA code to copy raw data into summary table

    Quote Originally Posted by JeteMc View Post
    If I understand correctly you would like to put the prelim salary slip onto the same sheet as the commission table. If that is a correct understanding then yes the formulas could all have the same references.
    The attached file demonstrates how this would work.
    Hi JeteMc,

    Sorry for the late reply, its been hectic at work.

    Is there a way that we can update the formulas to reference to a new workbook for the commission sheet for next month without having to change all 500 formulas manually?

    This month the workbook name is "Commission - October" & next month it will be "Commission - November".

    Thanks in advance.

    April

  20. #20
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,542

    Re: VBA code to copy raw data into summary table

    "Is there a way that we can update the formulas to reference to a new workbook for the commission sheet for next month without having to change all 500 formulas manually?"

    If the prelim and commission are going to be in different workbooks, it would be better to use Jindon's VBA solution.

    Best of luck.

  21. #21
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: VBA code to copy raw data into summary table

    Only if the file name & the sheet name for Commission_xxx.xls are identical as you uploaded.
    Please Login or Register  to view this content.

+ 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. help on vba code to Create table of summary from list of data
    By sarva200481 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2019, 06:34 AM
  2. [SOLVED] Summary of a particular Code from Data table - outlined per entry
    By mjsmith82 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-26-2015, 08:12 PM
  3. [SOLVED] VBA Code to copy data from dynamic list of worksheet names into summary sheet
    By dt_org in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-21-2014, 10:03 AM
  4. Replies: 1
    Last Post: 03-28-2013, 02:49 PM
  5. [SOLVED] Need Help w/ Code for Copy/Paste data for a Summary Worksheet
    By Langie in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-26-2013, 05:21 PM
  6. Copy table information into Summary Sheet and All Data Sheet
    By stage in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2011, 03:54 PM
  7. VBA Code to create summary table and Chart
    By KPK in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-01-2010, 05:40 AM

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