Help with a VBA I’m working on

Nova88

New Member
Joined
Nov 5, 2024
Messages
5
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
I’m trying to create a VBA script to help with a monthly report I have to complete.
I have quite a few sheets in a workbook with a named table in each sheet, these are named SheetName_Table with headers of Address and month names Jan to Dec. For example sheet - Level1 , Table - Level1_Table. The script has to run through a report generated by a lighting control program and return the values from its own table (Report_Table). The values come from 3 columns named Status, Test Requirement & Gear fault. If Status is a ✔ then return that value if it says see test requirement then return that column value if it says see gear fault return the gear fault column. I already have an Xlookup formula to do this but I’d like to automate it to loop through the report finding the Light Address in the workbook and return the relevant values from the above columns into each pages table for this month. If anyone can help I’d appreciate it. Screenshots won’t attach as they are apparently too big
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hard to imagine and might lead to wrong suggestion. You can create a mock up sample for helpers to visualize or you might not get any reply. :)
 
Upvote 0
These are some screen shots i was able to upload (Finally)
 

Attachments

  • IMG_5464.jpeg
    IMG_5464.jpeg
    152.6 KB · Views: 10
  • IMG_5470.jpeg
    IMG_5470.jpeg
    173.4 KB · Views: 11
  • IMG_5469.jpeg
    IMG_5469.jpeg
    149.3 KB · Views: 8
  • IMG_5468.jpeg
    IMG_5468.jpeg
    143.8 KB · Views: 9
Upvote 0
Sample File.xlsx
ABCDEFGH
1079PromenadeLCM 2000 Bus 1 Ballast 11 Inverter 25May 12/10/2024
1080PromenadeLCM 2000 Bus 1 Ballast 9 Inverter 26Mar 6/10/2024
1081PromenadeLCM 2000 Bus 1 Ballast 8 Inverter 27Jul 20/7/2024 See test requirement 38
1082PromenadeLCM 2000 Bus 1 Ballast 7 Inverter 28Jun 18/10/2024 See gear fault130
1083PromenadeLCM 2000 Bus 1 Inverter 29Nov 5/10/2024
1084PromenadeLCM 2000 Bus 1 Inverter 30Oct 27/10/2024
1085PromenadeLCM 2000 Bus 2 Ballast 9 Inverter 22Jan 27/10/2024
1086PromenadeLCM 2000 Bus 2 Ballast 8 Inverter 23Feb 5/10/2024
1087PromenadeLCM 2000 Bus 2 Ballast 7 Inverter 24Jun 13/10/2024
1088PromenadeLCM 2000 Bus 2 Ballast 6 Inverter 25Oct 27/10/2024
1089PromenadeLCM 2000 Bus 2 Ballast 5 Inverter 26Jul 19/10/2024
1090PromenadeLCM 2000 Bus 2 Ballast 4 Inverter 27Sep 25/10/2024
1091PromenadeLCM 2000 Bus 2 Ballast 3 Inverter 28Jun 18/10/2024
1092PromenadeLCM 2000 Bus 2 Ballast 2 Inverter 29Jun 4/10/2024
1093PromenadeLCM 2000 Bus 2 Ballast 1 Inverter 30Aug 20/10/2024
1094PromenadeLCM 2030 Bus 1 Ballast 23 Inverter 41May 12/10/2024
1095PromenadeLCM 2030 Bus 1 Ballast 24 Inverter 42May 6/10/2024
1096PromenadeLCM 2030 Bus 1 Ballast 26 Inverter 43May 4/10/2024
1097PromenadeLCM 2030 Bus 1 Ballast 25 Inverter 44Aug 20/10/2024
1098PromenadeLCM 2030 Bus 1 Ballast 21 Inverter 45Oct 22/10/2024 See gear fault13152
1099PromenadeLCM 2030 Bus 1 Ballast 6 Inverter 46Oct 27/10/2024
1100PromenadeLCM 2030 Bus 1 Ballast 19 Inverter 48Aug 20/10/2024
1101PromenadeLCM 2030 Bus 1 Ballast 16 Inverter 50Oct 27/10/2024
1102PromenadeLCM 2030 Bus 1 Ballast 15 Inverter 51Oct 5/10/2024 See test requirement 39
1103PromenadeLCM 2030 Bus 1 Ballast 12 Inverter 52Sep 11/10/2024 See test requirement 39
1104PromenadeLCM 2030 Bus 1 Ballast 10 Inverter 54Jul 19/10/2024
1105PromenadeLCM 2030 Bus 1 Ballast 9 Inverter 55Jun 13/10/2024
Report
Emergency%20Light%20Testing%20Log%20Book%202024(AutoRecovered).xlsm
BCDEFGHIJKLM
7Unit LocationJanFebMarAprMayJunJulAugSepOctNov
8LCM 2000 Bus 1 Ballast 11 Inverter 25
9LCM 2000 Bus 1 Ballast 9 Inverter 26
10LCM 2000 Bus 1 Ballast 8 Inverter 27131313131313383838
11LCM 2000 Bus 1 Ballast 7 Inverter 289991313131313
12LCM 2000 Bus 1 Inverter 29
13LCM 2000 Bus 1 Inverter 3037
14LCM 2000 Bus 2 Ballast 9 Inverter 22
15LCM 2000 Bus 2 Ballast 8 Inverter 23
16LCM 2000 Bus 2 Ballast 7 Inverter 24
17LCM 2000 Bus 2 Ballast 6 Inverter 25
18LCM 2000 Bus 2 Ballast 5 Inverter 26
19LCM 2000 Bus 2 Ballast 4 Inverter 27
20LCM 2000 Bus 2 Ballast 3 Inverter 28
21LCM 2000 Bus 2 Ballast 2 Inverter 29
22LCM 2000 Bus 2 Ballast 1 Inverter 30
23LCM 2030 Bus 1 Ballast 23 Inverter 411414
24LCM 2030 Bus 1 Ballast 24 Inverter 42
25LCM 2030 Bus 1 Ballast 26 Inverter 43
26LCM 2030 Bus 1 Ballast 25 Inverter 44
27LCM 2030 Bus 1 Ballast 21 Inverter 451313131313
28LCM 2030 Bus 1 Ballast 6 Inverter 46
29LCM 2030 Bus 1 Ballast 19 Inverter 48
Promenade
Cells with Data Validation
CellAllowCriteria
C8:M29List=Tick
Sample File.xlsx
D
1Tick:
2
3
43
59
610
713
814
916
1018
1123
1236
1337
1438
1539
1644
1745
1861
1975
2079
2180
2281
2388
2489
2590
2691
2792
2895
29D0
30D1
31D2
32G9
33
34
Data
 
Upvote 0
You have a workbook with many worksheets. One of the sheet called Result. Other sheet has its own name and one of them is Promenade as shown in example. Other sheet names are not stated here. You want to loop through Status column and transfer the finding to each individual sheets named in column Area (as in picture)

Hope my understanding is correct up this point.

In Promenade sheet, you have Unit Location and month columns. Does the month related to the column Month in sheet Report and has nothing to do with date in sheet Report column D? I think once this is automated, Data Validation is no longer needed, right?
 
Upvote 0
Yeah there’s a lot more sheets in the workbook, I didn’t want to include them all as there’s 30 of them. It needs to loop through the sheet names in Column A finding the addresses that are in column B in those sheets and return the result from column E if it’s a tick, if it as another result then return the result from the column it has written. Yeah preferably if it works I can get rid of the data validation. The months that are in column C are only needed for the yellow filled boxes which I’m going to do a different code for, so it needs to match the month from column D and put the data in the month column on the sheet that matches the floor. I know it seem mad but I go through this manually every month and it takes a fair bit of time. I do have an xlookup formula that speeds it up a bit but I’d like to have other colleagues be able click a button to run a code and not break all the work I’ve done on this book
 
Upvote 0
Sorry for late reply. I was busy, I'm not sure if I fully understand everything but here is the preliminary code
VBA Code:
Sub CompileReport()

Dim eRow As Long, nCol As Long
Dim cell As Range, rngArea As Range, Found As Range, rngFind As Range
Dim ws As Worksheet, wsReport As Worksheet
Dim wb As Workbook

Set wb = ThisWorkbook
Set wsReport = wb.Sheets("Report")
eRow = wsReport.Range("A1").End(xlDown).Row                ' Get End of row for column A in Sheet Report
Set rngArea = wsReport.Range("A2", "A" & eRow)

For Each cell In rngArea
    Set ws = wb.Sheets(cell.Value)
    eRow = ws.Range("B1").End(xlDown).Row
    Set rngFind = ws.Range("B2", "A" & eRow)
    Set Found = rngFind.Find(wsReport.Range("B" & cell.Row))
    If Not Found Is Nothing Then
        nCol = Month(wsReport.Range("D" & cell.Row)) + 2        ' Add 2 to offset number generated by Month function
        ws.Cells(Found.Row, nCol) = wsReport.Range("E" & cell.Row)
    End If
Next
       
End Sub

Time to go home. End of working hour in my time zone :)
 
Upvote 1
Solution
Sorry for late reply. I was busy, I'm not sure if I fully understand everything but here is the preliminary code
VBA Code:
Sub CompileReport()

Dim eRow As Long, nCol As Long
Dim cell As Range, rngArea As Range, Found As Range, rngFind As Range
Dim ws As Worksheet, wsReport As Worksheet
Dim wb As Workbook

Set wb = ThisWorkbook
Set wsReport = wb.Sheets("Report")
eRow = wsReport.Range("A1").End(xlDown).Row                ' Get End of row for column A in Sheet Report
Set rngArea = wsReport.Range("A2", "A" & eRow)

For Each cell In rngArea
    Set ws = wb.Sheets(cell.Value)
    eRow = ws.Range("B1").End(xlDown).Row
    Set rngFind = ws.Range("B2", "A" & eRow)
    Set Found = rngFind.Find(wsReport.Range("B" & cell.Row))
    If Not Found Is Nothing Then
        nCol = Month(wsReport.Range("D" & cell.Row)) + 2        ' Add 2 to offset number generated by Month function
        ws.Cells(Found.Row, nCol) = wsReport.Range("E" & cell.Row)
    End If
Next
      
End Sub

Time to go home. End of working hour in my time zone :)
Worked like a charm. Thanks for the help. Really appreciate it
 
Upvote 0

Forum statistics

Threads
1,223,627
Messages
6,173,424
Members
452,515
Latest member
Alicedonald9

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