Hits, misses and false alarms monthly summary

drefiek2

Board Regular
Joined
Apr 23, 2023
Messages
72
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I need help creating a 'verification' monthly summary table and I will try to explain what I want using an example.
I have a spreadsheet with dates in column B starting from row 6 (1st Jan 2025 - 31st Dec 2025), these dates are merged cells over two rows, so rather than 365 rows there are 730 rows.
I have cities in Europe along row 5 columns D to J.
For each date I have 'Sunny Forecast' and 'Observation', what someone will do is forecast whether it will be sunny in those cities on that date and either put a 0 for yes (green flag) or a 1 for no (red flag).
The next day they will verify whether it was sunny or not, by again putting a 0 or 1.
If both are 0 for that date then it is a 'hit', if both are 1 for that date then it is also a 'hit', if the forecast is a 0 but the observation is a 1 then it is a 'miss', if the forecast is a 1 but the observation is a 0 then it is a 'false alarm'. This probably sounds strange but it is just an example!
Essentially what I want to be able to do is in a blank table on another sheet, select a month from a drop down box above the table, and then for the table to auto-populate whether for each date and for each city it was a hit, miss or false alarm, by automatically entering either a H, M or FA in the cell. Again I'd like cities along the top and dates along the side.
I suppose there needs to be an IF formula (with some ISNUMBER statements too) checking whether cells are equal, more than or less than 0 or 1? Or is there a better way to do it, I've got no idea, so any help would be very much appreciated.
Hopefully that makes sense, I've attached a screenshot of the top of the spreadsheet for reference.
 

Attachments

  • Screenshot 2025-03-05 201018.png
    Screenshot 2025-03-05 201018.png
    14.3 KB · Views: 13
Assuming your forecast data is located in the "ForecastData" sheet, and the output to be displayed in the "Summary" sheet. When you enter a month in cell B1 of the "Summary" sheet, the corresponding output is generated accordingly like below with your conditions. Is this what you are looking for? You want to try VBA

Forcast Data.xlsm
BCDEFGHIJ
5DateTypeLondonBerlinParisMadridAthensLisbonRome
61/1/2025Sunny Forecast0011011
7Observation1010011
81/2/2025Sunny Forecast0100100
9Observation1101101
101/3/2025Sunny Forecast1100110
11Observation1011001
ForecastData

Forcast Data.xlsm
ABCDEFGHI
1MonthJanuary
2DateTypeLondonBerlinParisMadridAthensLisbonRome
31/1/2025Sunny ForecastMHHFAHHH
4Observation
51/2/2025Sunny ForecastMHHMHHM
6Observation
71/3/2025Sunny ForecastHFAMMFAFAM
8Observation
Summary
 
Upvote 0
Assuming your forecast data is located in the "ForecastData" sheet, and the output to be displayed in the "Summary" sheet. When you enter a month in cell B1 of the "Summary" sheet, the corresponding output is generated accordingly like below with your conditions. Is this what you are looking for? You want to try VBA

Forcast Data.xlsm
BCDEFGHIJ
5DateTypeLondonBerlinParisMadridAthensLisbonRome
61/1/2025Sunny Forecast0011011
7Observation1010011
81/2/2025Sunny Forecast0100100
9Observation1101101
101/3/2025Sunny Forecast1100110
11Observation1011001
ForecastData

Forcast Data.xlsm
ABCDEFGHI
1MonthJanuary
2DateTypeLondonBerlinParisMadridAthensLisbonRome
31/1/2025Sunny ForecastMHHFAHHH
4Observation
51/2/2025Sunny ForecastMHHMHHM
6Observation
71/3/2025Sunny ForecastHFAMMFAFAM
8Observation
Summary
Yes that is exactly what I am looking for, I am just not sure what VBA code or formulas I need to do it, are you able to help with it? I have never written any VBA from scratch before and I'm not sure where to start.
 
Upvote 0
Please try this, [Sheet names and ranges should be considered]
VBA Code:
Sub ForecastSummary()

    Dim wsData As Worksheet, wsSummary As Worksheet
    Dim selectedMonth As String
    Dim lastRow As Long, summaryRow As Long, dataRow As Long
    Dim cityCol As Integer, summaryCol As Integer
    Dim currentMonth As String
    Dim matchFound As Boolean
    Dim forecastVal As Variant, observationVal As Variant
    Dim result As String
    
    Set wsData = ThisWorkbook.Sheets("ForecastData")
    Set wsSummary = ThisWorkbook.Sheets("Summary")
    
    selectedMonth = Trim(UCase(wsSummary.Range("B1").Value))
    If selectedMonth = "" Then
        MsgBox "Please select a month.", vbExclamation, "No Month Selected"
        Exit Sub
    End If
    
    lastRow = wsData.Cells(wsData.Rows.Count, 2).End(xlUp).Row

    wsSummary.Range("A3:I1000").ClearContents
    wsSummary.Range("A3:I1000").UnMerge
    
    wsSummary.Cells(2, 1).Value = "Date"
    wsSummary.Cells(2, 2).Value = "Type"
    wsSummary.Cells(2, 3).Value = "London"
    wsSummary.Cells(2, 4).Value = "Berlin"
    wsSummary.Cells(2, 5).Value = "Paris"
    wsSummary.Cells(2, 6).Value = "Madrid"
    wsSummary.Cells(2, 7).Value = "Athens"
    wsSummary.Cells(2, 8).Value = "Lisbon"
    wsSummary.Cells(2, 9).Value = "Rome"

    wsSummary.Range("A3:A1000").HorizontalAlignment = xlCenter
    wsSummary.Range("A3:A1000").VerticalAlignment = xlCenter
    
    summaryRow = 3
    matchFound = False
    
    For dataRow = 6 To lastRow Step 2
        If Not IsEmpty(wsData.Cells(dataRow, 2).Value) And IsDate(wsData.Cells(dataRow, 2).Value) Then
            
            currentMonth = Trim(UCase(Format(wsData.Cells(dataRow, 2).Value, "MMMM")))
            
            Debug.Print "Checking Row:", dataRow, "Date:", wsData.Cells(dataRow, 2).Value, "Extracted Month:", currentMonth
            Debug.Print "Selected Month from B1:", selectedMonth
            
            If currentMonth = selectedMonth Then
                wsSummary.Range(wsSummary.Cells(summaryRow, 1), wsSummary.Cells(summaryRow + 1, 1)).Merge
                wsSummary.Cells(summaryRow, 1).Value = wsData.Cells(dataRow, 2).Value
                
                wsSummary.Cells(summaryRow, 2).Value = wsData.Cells(dataRow, 3).Value
                wsSummary.Cells(summaryRow + 1, 2).Value = wsData.Cells(dataRow + 1, 3).Value
                
                summaryCol = 3
                For cityCol = 4 To 10
                    forecastVal = wsData.Cells(dataRow, cityCol).Value
                    observationVal = wsData.Cells(dataRow + 1, cityCol).Value
                    
                    If IsNumeric(forecastVal) And IsNumeric(observationVal) Then
                        If forecastVal = 0 And observationVal = 0 Then
                            result = "H"
                        ElseIf forecastVal = 1 And observationVal = 1 Then
                            result = "H"
                        ElseIf forecastVal = 0 And observationVal = 1 Then
                            result = "M"
                        ElseIf forecastVal = 1 And observationVal = 0 Then
                            result = "FA"
                        Else
                            result = "?"
                        End If
                    Else
                        result = "N/A"
                    End If
                    
                    wsSummary.Range(wsSummary.Cells(summaryRow, summaryCol), wsSummary.Cells(summaryRow + 1, summaryCol)).Merge
                    wsSummary.Cells(summaryRow, summaryCol).Value = result
                    
                    With wsSummary.Range(wsSummary.Cells(summaryRow, summaryCol), wsSummary.Cells(summaryRow + 1, summaryCol))
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        .Font.Bold = True
                    End With

                    summaryCol = summaryCol + 1
                Next cityCol
                
                summaryRow = summaryRow + 2
                matchFound = True
            End If
        End If
    Next dataRow
    
    If Not matchFound Then
        MsgBox "No matching data for " & selectedMonth & ". Ensure the month exists in Column B.", vbExclamation, "No Data Found"
        Exit Sub
    End If

    MsgBox "Summary table updated for " & selectedMonth, vbInformation, "Update Complete"

End Sub
 
Upvote 0
Solution
Please try this, [Sheet names and ranges should be considered]
VBA Code:
Sub ForecastSummary()

    Dim wsData As Worksheet, wsSummary As Worksheet
    Dim selectedMonth As String
    Dim lastRow As Long, summaryRow As Long, dataRow As Long
    Dim cityCol As Integer, summaryCol As Integer
    Dim currentMonth As String
    Dim matchFound As Boolean
    Dim forecastVal As Variant, observationVal As Variant
    Dim result As String
   
    Set wsData = ThisWorkbook.Sheets("ForecastData")
    Set wsSummary = ThisWorkbook.Sheets("Summary")
   
    selectedMonth = Trim(UCase(wsSummary.Range("B1").Value))
    If selectedMonth = "" Then
        MsgBox "Please select a month.", vbExclamation, "No Month Selected"
        Exit Sub
    End If
   
    lastRow = wsData.Cells(wsData.Rows.Count, 2).End(xlUp).Row

    wsSummary.Range("A3:I1000").ClearContents
    wsSummary.Range("A3:I1000").UnMerge
   
    wsSummary.Cells(2, 1).Value = "Date"
    wsSummary.Cells(2, 2).Value = "Type"
    wsSummary.Cells(2, 3).Value = "London"
    wsSummary.Cells(2, 4).Value = "Berlin"
    wsSummary.Cells(2, 5).Value = "Paris"
    wsSummary.Cells(2, 6).Value = "Madrid"
    wsSummary.Cells(2, 7).Value = "Athens"
    wsSummary.Cells(2, 8).Value = "Lisbon"
    wsSummary.Cells(2, 9).Value = "Rome"

    wsSummary.Range("A3:A1000").HorizontalAlignment = xlCenter
    wsSummary.Range("A3:A1000").VerticalAlignment = xlCenter
   
    summaryRow = 3
    matchFound = False
   
    For dataRow = 6 To lastRow Step 2
        If Not IsEmpty(wsData.Cells(dataRow, 2).Value) And IsDate(wsData.Cells(dataRow, 2).Value) Then
           
            currentMonth = Trim(UCase(Format(wsData.Cells(dataRow, 2).Value, "MMMM")))
           
            Debug.Print "Checking Row:", dataRow, "Date:", wsData.Cells(dataRow, 2).Value, "Extracted Month:", currentMonth
            Debug.Print "Selected Month from B1:", selectedMonth
           
            If currentMonth = selectedMonth Then
                wsSummary.Range(wsSummary.Cells(summaryRow, 1), wsSummary.Cells(summaryRow + 1, 1)).Merge
                wsSummary.Cells(summaryRow, 1).Value = wsData.Cells(dataRow, 2).Value
               
                wsSummary.Cells(summaryRow, 2).Value = wsData.Cells(dataRow, 3).Value
                wsSummary.Cells(summaryRow + 1, 2).Value = wsData.Cells(dataRow + 1, 3).Value
               
                summaryCol = 3
                For cityCol = 4 To 10
                    forecastVal = wsData.Cells(dataRow, cityCol).Value
                    observationVal = wsData.Cells(dataRow + 1, cityCol).Value
                   
                    If IsNumeric(forecastVal) And IsNumeric(observationVal) Then
                        If forecastVal = 0 And observationVal = 0 Then
                            result = "H"
                        ElseIf forecastVal = 1 And observationVal = 1 Then
                            result = "H"
                        ElseIf forecastVal = 0 And observationVal = 1 Then
                            result = "M"
                        ElseIf forecastVal = 1 And observationVal = 0 Then
                            result = "FA"
                        Else
                            result = "?"
                        End If
                    Else
                        result = "N/A"
                    End If
                   
                    wsSummary.Range(wsSummary.Cells(summaryRow, summaryCol), wsSummary.Cells(summaryRow + 1, summaryCol)).Merge
                    wsSummary.Cells(summaryRow, summaryCol).Value = result
                   
                    With wsSummary.Range(wsSummary.Cells(summaryRow, summaryCol), wsSummary.Cells(summaryRow + 1, summaryCol))
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        .Font.Bold = True
                    End With

                    summaryCol = summaryCol + 1
                Next cityCol
               
                summaryRow = summaryRow + 2
                matchFound = True
            End If
        End If
    Next dataRow
   
    If Not matchFound Then
        MsgBox "No matching data for " & selectedMonth & ". Ensure the month exists in Column B.", vbExclamation, "No Data Found"
        Exit Sub
    End If

    MsgBox "Summary table updated for " & selectedMonth, vbInformation, "Update Complete"

End Sub
I tested it and it works when assigned to a button, thanks very much, hugely appreciated!
Is there a way for it to run the code just by selecting the month from a drop down list in B1, rather than pressing a button?
 
Upvote 0
Please drop this script in "Summary" sheet like below, {not in module}
1741307693474.png

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("B1")) Is Nothing Then
        If Target.Cells.Count = 1 And Target.Value <> "" Then
            Application.EnableEvents = False
            Call ForecastSummary
            Application.EnableEvents = True
        End If
    End If
End Sub
 
Upvote 0
Please drop this script in "Summary" sheet like below, {not in module}
View attachment 123057
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("B1")) Is Nothing Then
        If Target.Cells.Count = 1 And Target.Value <> "" Then
            Application.EnableEvents = False
            Call ForecastSummary
            Application.EnableEvents = True
        End If
    End If
End Sub
It works, thanks very much!! Huge appreciated.
 
Upvote 0
Sorry one more question if I may.... if there are any missing values/empty cells in the forecast data table, whether that is Sunny Forecast, Observation, or both cells missing/empty for a particular day, I would like the summary table entry for that day to be empty/blank as well. At the moment it still reports it as a Hit even when blank.

The reason for this is I have a formula at the bottom which calculates the number of H, M and FAs for each city and then do some math based on the number of 'filled in complete' days.
 
Upvote 0
If using your 365 version, would you be interested in a formula approach? Could probably be adapted if you need it to work in your 2021 version as well.
(This is a smaller data size but easily expandable to your full data ranges.)

drefiek2.xlsm
BCDEFGHIJ
5DateTypeLondonBerlinParisMadridAthensLisbonRome
61/01/2025Sunny Forecast0011011
7Observation1010011
82/01/2025Sunny Forecast0100100
9Observation1101101
103/02/2025Sunny Forecast110110
11Observation10001
124/02/2025Sunny Forecast001101
13Observation1010011
145/02/2025Sunny Forecast0100100
15Observation1101101
163/03/2025Sunny Forecast1100110
17Observation1011001
Sheet1


Cell A1 below would be the month drop-down.

drefiek2.xlsm
ABCDEFGH
1February
2
3LondonBerlinParisMadridAthensLisbonRome
43/02/2025HFAFAFAM
54/02/2025MHHFAHH
65/02/2025MHHMHHM
7
Sheet2
Cell Formulas
RangeFormula
B3:H3B3=Sheet1!D5:J5
A4:H6A4=LET(b,Sheet1!B6:B17,x,Sheet1!D6:J17,y,IF(x="",2,x),d,TOCOL(IF(b="",1/0,IF(TEXT(b,"mmmm")=A1,b,1/0)),2),q,MATCH(A1,TEXT(b,"mmmm"),0)+SEQUENCE(ROWS(d),,,2),HSTACK(d,IFNA(SWITCH(--(CHOOSEROWS(y,q-1)&CHOOSEROWS(y,q)),0,"H",1,"M",10,"FA",11,"H"),"")))
Dynamic array formulas.
 
Upvote 0
Sorry one more question if I may.... if there are any missing values/empty cells in the forecast data table, whether that is Sunny Forecast, Observation, or both cells missing/empty for a particular day, I would like the summary table entry for that day to be empty/blank as well. At the moment it still reports it as a Hit even when blank.

The reason for this is I have a formula at the bottom which calculates the number of H, M and FAs for each city and then do some math based on the number of 'filled in complete' days.
A slight update for that, look for this part of the code and add the blank entry. Please cross check the code in box. {Also you can try the formula above}
1741313097163.png

VBA Code:
If IsEmpty(forecastVal) Or IsEmpty(observationVal) Then
                        result = ""  ' Blank entry
                    
                    ElseIf IsNumeric(forecastVal) And IsNumeric(observationVal) Then
                        If forecastVal = 0 And observationVal = 0 Then
                            result = "H"
 
Upvote 0

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