Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
Hi good afternoon, all I'm trying to count when CommandButton3 is clicked in UserForm2 ComboBox2 value="Holiday" or "Stores" to count eachtime in UserForm1 TextBox10, but the code I have below doesn't seem to be counting anything. Please can you help.
VBA Code:
Private Sub CommandButton3_Click()
If TextBox3.Value = "" Then
MsgBox "Please enter 'Notes'"
Exit Sub
End If
Dim emptyRow As Long
Dim holidayCount As Integer
Dim storesCount As Integer
Dim i As Integer
With ThisWorkbook.Sheets("Raised")
emptyRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
.Cells(emptyRow, 1).Value = IIf(ComboBox1.Value = "", "NA", ComboBox1.Value)
.Cells(emptyRow, 2).Value = IIf(TextBox1.Value = "", "NA", TextBox1.Value)
.Cells(emptyRow, 3).Value = IIf(TextBox2.Value = "", "NA", TextBox2.Value)
.Cells(emptyRow, 4).Value = IIf(ComboBox2.Value = "", "NA", ComboBox2.Value)
.Cells(emptyRow, 5).Value = IIf(TextBox3.Value = "", "NA", TextBox3.Value)
End With
' Count occurrences of "Holiday" and "Stores" in ComboBox2 of UserForm2
For i = 0 To UserForm2.ComboBox2.ListCount - 1
If UserForm2.ComboBox2.List(i) = "Holiday" Then
holidayCount = holidayCount + 1
ElseIf UserForm2.ComboBox2.List(i) = "Stores" Then
storesCount = storesCount + 1
End If
Next i
' Update TextBox10 of UserForm1 with the counts of "Holiday" and "Stores"
UserForm1.TextBox10.Value = holidayCount + storesCount
' Unload UserForm2
Unload Me
' Show UserForm1
If Not UserForm1.Visible Then
UserForm1.Show
End If
End Sub