VBA - Autofill table based on multiple cell entries

MikeLangley

New Member
Joined
Mar 13, 2019
Messages
2
I hope that someone can assist me with some VBA code to cover a little problem I am having?

I work for a company that engineers visiting sites on a daily basis to conduct air tests, sound tests, vent tests etc. and we are looking to map their jobs cumulatively month by month.

Importing the data from our CRM is covered, as is the geocoding, however I am having difficulty when trying to create a method to view the data more easily. I am trying to display the records in a table based on the particular service and month that it was carried out.

So I have 2 sheets, 1 for data containing the full cumulative list of jobs, and the 2nd for viewing a snapshot. The data page has the unique job reference, the name of the engineer, the name of the service being carried out and the site location.

The 2nd sheet contains two dropdowns and the table headings below. the dropdowns control the service and date. What I need is for the table to fill based on the entries in those 2 cells.


Can anyone help?

Mike.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You could upload a copy of your file with some examples, to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
In the viewer sheet, you could put the data in the following way with formulas too.





Excel Workbook
ABCDEFGHIJ
1ShowCommercial Air TestingFromFebruaryServiceDateDate
2Commercial Air Testing>=43497 
3Job RefSite PostcodeServiceEngineerNo. of TestsDate01/02/201928/02/2019
4JB-011683IP12 4LHCommercial Air TestingKeith Markham122/02/2019
5JB-011683IP12 4LHCommercial Air TestingKeith Markham122/02/2019
Viewer


I'm applying an advanced filter, that way the queries are faster.


Put the following macro in the events of your Viewer sheet:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim sh1 As Worksheet, sh2 As Worksheet, j As Long
    
    Set sh1 = Sheets("Data")
    Set sh2 = Sheets("Viewer")
    If Not Intersect(Target, Range("B1,E1")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Range("E1").Value <> "" Then
            For j = 1 To 12
                If LCase(Format(DateSerial(Year(Date), j, 1), "mmmm")) = LCase(Range("E1").Value) Then
                    sh2.Range("I3") = DateSerial(Year(Date), j, 1)
                    sh2.Range("J3") = DateSerial(Year(Date), j, Day(DateSerial(Year(Date), j + 1, 1) - 1))
                End If
            Next
         End If
        sh1.Range("A1:F6").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _
            CriteriaRange:=sh2.Range("H1:J2"), CopyToRange:=sh2.Range("A3:F3"), Unique:=False
    End If
End Sub

(Right click the tab of the sheet you want this to work, select view code & paste the code into the window that opens up.)


test your file:
https://www.dropbox.com/s/80k9ohckvffsc6n/Sample.xlsm?dl=0
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,914
Members
449,054
Latest member
luca142

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