R
Richhall
Hi, As per previous post I have some fields in a userform that do a
COUNTIF of values in a worksheet. However, as I change worksheet the
userform doesn't amend the values. I've tried unloading and reloading
the userform in the Worksheet_Activate but the values remain in there,
Ive also tried userform Activate and Initialise. How do I get the
values to refresh on changing worksheet please?
Private Sub Worksheet_Activate()
MyForm.Hide
Unload MyForm
Load MyForm
MyForm.Show
End Sub
Private Sub UserForm_Initialize()
Dim BananaBox, AppleBox, PearBox
Set ws = ActiveSheet
Me.BananaBox = Application.WorksheetFunction. _
CountIf(ws.Range("$G$9:$H$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$N$9:$O$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$U$9:$V$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AB$9:$AC$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AI$9:$AJ$44"), "Banana")
Me.AppleBox = Application.WorksheetFunction. _
CountIf(ws.Range("$G$9:$H$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$N$9:$O$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$U$9:$V$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AB$9:$AC$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AI$9:$AJ$44"), "Apple")
End Sub
COUNTIF of values in a worksheet. However, as I change worksheet the
userform doesn't amend the values. I've tried unloading and reloading
the userform in the Worksheet_Activate but the values remain in there,
Ive also tried userform Activate and Initialise. How do I get the
values to refresh on changing worksheet please?
Private Sub Worksheet_Activate()
MyForm.Hide
Unload MyForm
Load MyForm
MyForm.Show
End Sub
Private Sub UserForm_Initialize()
Dim BananaBox, AppleBox, PearBox
Set ws = ActiveSheet
Me.BananaBox = Application.WorksheetFunction. _
CountIf(ws.Range("$G$9:$H$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$N$9:$O$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$U$9:$V$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AB$9:$AC$44"), "Banana") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AI$9:$AJ$44"), "Banana")
Me.AppleBox = Application.WorksheetFunction. _
CountIf(ws.Range("$G$9:$H$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$N$9:$O$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$U$9:$V$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AB$9:$AC$44"), "Apple") +
Application.WorksheetFunction. _
CountIf(ws.Range("$AI$9:$AJ$44"), "Apple")
End Sub