VBA Daily Sales Placement

BijanBorazjani

New Member
Joined
Oct 22, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I am trying to build a VBA code that can automatically place the previous days sales into the corresponding employees sheet based on the daily upload. The report will have the employee name in the daily sales as well as their own corresponding sheet. I would like it to be a click of a button that looks up the day of the report and places the correct data in the corresponding employees sheet.

Book1
ABCD
1Call SalesIn Store SalesTotal Sales
2Employee Name
3Employee 113334
4Emplyoee 223335
5Employee 333336
6Total Sales699105
7
8
9
10Report Date8/2/2022
Daily Sales
Cell Formulas
RangeFormula
D3:D5D3=SUM(B3:C3)
B6:D6B6=SUM(B3:B5)
B10B10=TODAY()-1


Book1
ABCDEFGHIJKLMNOP
1Week 1TicketsCallsSurvey ScoreWeek 2TicketsCallsSurvey ScoreWeek 3TicketsCallsSurvey ScoreWeek 4TicketsCallsSurvey Score
21/3/20221/10/20221/17/20221/24/2022
31/4/20221/11/20221/18/20221/25/2022
41/5/20221/12/20221/19/20221/26/2022
51/6/20221/13/20221/20/20221/27/2022
61/7/20221/14/20221/21/20221/28/2022
7
8Week 5TicketsCallsSurvey ScoreWeek 6TicketsCallsSurvey ScoreWeek 7TicketsCallsSurvey ScoreWeek 8TicketsCallsSurvey Score
91/31/20222/7/20222/14/20222/21/2022
102/1/20222/8/20222/15/20222/22/2022
112/2/20222/9/20222/16/20222/23/2022
122/3/20222/10/20222/17/20222/24/2022
132/4/20222/11/20222/18/20222/25/2022
14
15Week 9Week 10Week 11Week 12TicketsCallsSurvey Scores
162/28/20223/7/20223/14/20223/21/2022
173/1/20223/8/20223/15/20223/22/2022
183/2/20223/9/20223/16/20223/23/2022
193/3/20223/10/20223/17/20223/24/2022
203/4/20223/11/20223/18/20223/25/2022
21
22Week 13TicketsCallsSurvey ScoreWeek 14TicketsCallsSurvey ScoreWeek 15TicketsCallsSurvey ScoreWeek 16TicketsCallsSurvey Score
233/28/20224/4/20224/11/20224/18/2022
243/29/20224/5/20224/12/20224/19/2022
253/30/20224/6/20224/13/20224/20/2022
263/31/20224/7/20224/14/20224/21/2022
274/1/20224/8/20224/15/20224/22/2022
28
29Week 17TicketsCallsSurvey ScoreWeek 18TicketsCallsSurvey ScoreWeek 19TicketsCallsSurvey ScoreWeek 20TicketsCallsSurvey Score
304/25/20225/2/20225/9/20225/16/2022
314/26/20225/3/20225/10/20225/17/2022
324/27/20225/4/20225/11/20225/18/2022
334/28/20225/5/20225/12/20225/19/2022
344/29/20225/6/20225/13/20225/20/2022
35
36Week 21TicketsCallsSurvey ScoreWeek 22TicketsCallsSurvey ScoreWeek 23TicketsCallsSurvey ScoreWeek 24TicketsCallsSurvey Score
375/23/20225/30/20226/6/20226/13/2022
385/24/20225/31/20226/7/20226/14/2022
395/25/20226/1/20226/8/20226/15/2022
405/26/20226/2/20226/9/20226/16/2022
415/27/20226/3/20226/10/20226/17/2022
42
43Week 25TicketsCallsSurvey ScoreWeek 26TicketsCallsSurvey ScoreWeek 27TicketsCallsSurvey ScoreWeek 28TicketsCallsSurvey Score
446/20/20226/27/20227/4/20227/11/2022
456/21/20226/28/20227/5/20227/12/2022
466/22/20226/29/20227/6/20227/13/2022
476/23/20226/30/20227/7/20227/14/2022
486/24/20227/1/20227/8/20227/15/2022
49
50Week 29TicketsCallsSurvey ScoreWeek 30TicketsCallsSurvey ScoreWeek 31TicketsCallsSurvey ScoreWeek 32TicketsCallsSurvey Score
517/18/20227/25/20228/1/20228/8/2022
527/19/20227/26/20228/2/20228/9/2022
537/20/20227/27/20228/3/20228/10/2022
547/21/20227/28/20228/4/20228/11/2022
557/22/20227/29/20228/5/20228/12/2022
56
57Week 33TicketsCallsSurvey ScoreWeek 34TicketsCallsSurvey ScoreWeek 35TicketsCallsSurvey ScoreWeek 36TicketsCallsSurvey Score
588/15/20228/22/20228/29/20229/5/2022
598/16/20228/23/20228/30/20229/6/2022
608/17/20228/24/20228/31/20229/7/2022
618/18/20228/25/20229/1/20229/8/2022
628/19/20228/26/20229/2/20229/9/2022
63
64Week 37TicketsCallsSurvey ScoreWeek 38TicketsCallsSurvey ScoreWeek 39TicketsCallsSurvey ScoreWeek 40TicketsCallsSurvey Score
659/12/20229/19/20229/26/202210/3/2022
669/13/20229/20/20229/27/202210/4/2022
679/14/20229/21/20229/28/202210/5/2022
689/15/20229/22/20229/29/202210/6/2022
699/16/20229/23/20229/30/202210/7/2022
70
71Week 41TicketsCallsSurvey ScoreWeek 42TicketsCallsSurvey ScoreWeek 43TicketsCallsSurvey ScoreWeek 44TicketsCallsSurvey Score
7210/10/202210/17/202210/24/202210/31/2022
7310/11/202210/18/202210/25/202211/1/2022
7410/12/202210/19/202210/26/202211/2/2022
7510/13/202210/20/202210/27/202211/3/2022
7610/14/202210/21/202210/28/202211/4/2022
77
78Week 45TicketsCallsSurvey ScoreWeek 46TicketsCallsSurvey ScoreWeek 47TicketsCallsSurvey ScoreWeek 48TicketsCallsSurvey Score
7911/7/202211/14/202211/21/202211/28/2022
8011/8/202211/15/202211/22/202211/29/2022
8111/9/202211/16/202211/23/202211/30/2022
8211/10/202211/17/202211/24/202212/1/2022
8311/11/202211/18/202211/25/202212/2/2022
84
85Week 49TicketsCallsSurvey ScoreWeek 50TicketsCallsSurvey ScoreWeek 51TicketsCallsSurvey ScoreWeek 52TicketsCallsSurvey Score
8612/5/202212/12/202212/19/202212/26/2022
8712/6/202212/13/202212/20/202212/27/2022
8812/7/202212/14/202212/21/202212/28/2022
8912/8/202212/15/202212/22/202212/29/2022
9012/9/202212/16/202212/23/202212/30/2022
91
Employee 1
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi,
There are "Call Sales" and "In Store Sales" in the Daily Sales sheet, but only Calls can be seen in the corresponding employees' sheet. So the following sample code would place only "Call Sales" data from the Daily Sales sheet to "Call" cell in each worksheet.
Assuming worksheet names for Employees are based on range A3 to A5 in the Daily Sales sheet. (*Found a typo in A5)

VBA Code:
Sub Sample1()
    Dim c As Range, rRptDate As Range, i As Long
    Dim shDaily As Worksheet, shEmp As Worksheet

    Set shDaily = ThisWorkbook.Sheets("Daily Sales")

    For i = 3 To 5    'Looping through employees sheet
        Set shEmp = ThisWorkbook.Sheets(shDaily.Cells(i, "A").Value)    'employee sheet
        Set c = shEmp.Range("A1:A" & shEmp.Cells(Rows.Count, 1).End(xlUp).Row)    'Date range
        Set c = Union(c, c.Offset(, 4), c.Offset(, 8), c.Offset(, 12))
        Set rRptDate = c.Find(shDaily.Range("B10").Value)
        If Not rRptDate Is Nothing Then
            rRptDate.Offset(, 2).Value = shDaily.Cells(i, "B").Value    'Calls
            'I have no idea where to put "In Store Sales"
        End If
    Next
End Sub
 
Upvote 0
Solution
Hi,
There are "Call Sales" and "In Store Sales" in the Daily Sales sheet, but only Calls can be seen in the corresponding employees' sheet. So the following sample code would place only "Call Sales" data from the Daily Sales sheet to "Call" cell in each worksheet.
Assuming worksheet names for Employees are based on range A3 to A5 in the Daily Sales sheet. (*Found a typo in A5)

VBA Code:
Sub Sample1()
    Dim c As Range, rRptDate As Range, i As Long
    Dim shDaily As Worksheet, shEmp As Worksheet

    Set shDaily = ThisWorkbook.Sheets("Daily Sales")

    For i = 3 To 5    'Looping through employees sheet
        Set shEmp = ThisWorkbook.Sheets(shDaily.Cells(i, "A").Value)    'employee sheet
        Set c = shEmp.Range("A1:A" & shEmp.Cells(Rows.Count, 1).End(xlUp).Row)    'Date range
        Set c = Union(c, c.Offset(, 4), c.Offset(, 8), c.Offset(, 12))
        Set rRptDate = c.Find(shDaily.Range("B10").Value)
        If Not rRptDate Is Nothing Then
            rRptDate.Offset(, 2).Value = shDaily.Cells(i, "B").Value    'Calls
            'I have no idea where to put "In Store Sales"
        End If
    Next
End Sub
This is perfect! Thank you so much. If you could, can you break down what everything does so that I can put it in my memory for later?
 
Upvote 0
Glad to hear it works. I hope that some adding comments would help your understanding of what this code does.

VBA Code:
Sub Sample1()
'Define Variables(Variable is a storage location within the computer's memory)
'Explicitly declaring variables and data types may result in more efficient and faster macros.
    Dim c As Range    'Define "Date" ranges in each employee worksheet
    Dim rRptDate As Range    'A found date cell as a result of the Find method
    Dim i As Long    'A counter for looping
    Dim shDaily As Worksheet    'A Variable to improve readability.
    Dim shEmp As Worksheet  'A Variable to improve readability.

'This variable can be used the same as a worksheet after the following line.
    Set shDaily = ThisWorkbook.Sheets("Daily Sales")


    'Looping through employees sheet.
    'There is information for employees' names in A3 to A5 in the "Daily Sales" sheet,
    '    so using those to define each corresponding employee sheet.
    For i = 3 To 5
        'define employee sheet
        Set shEmp = ThisWorkbook.Sheets(shDaily.Cells(i, "A").Value)
        'Specify the search destination range for Date in the corresponding employee sheet
        Set c = shEmp.Range("A1:A" & shEmp.Cells(Rows.Count, 1).End(xlUp).Row)
        Set c = Union(c, c.Offset(, 4), c.Offset(, 8), c.Offset(, 12))
        'Finding the Date cell for putting data from Daily Sales" sheet
        Set rRptDate = c.Find(shDaily.Range("B10").Value)
       
        If Not rRptDate Is Nothing Then 'If the Date is found...
            rRptDate.Offset(, 2).Value = shDaily.Cells(i, "B").Value    'Calls
            'I have no idea where to put "In Store Sales"
        End If
    Next
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,320
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top