ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Hi,
I am using the following code.
Using the line of code for Me.TextBox1 as an example you will see the text in question shows HONDA MC KEY #11
This is a typo & should be #1 NOT #11 so when the userform is open the TextBox in question shows 0
If i correct the #11 to #1 then the TextBox shows 27 of which is the correct value.
Now there will be times when i add to the code below the correct TextBox value will be 0 & will be correct BUT i wish for typos to be shown like ERROR or NOT FOUND as to make it stand out from the 0 value
I am using the following code.
Using the line of code for Me.TextBox1 as an example you will see the text in question shows HONDA MC KEY #11
This is a typo & should be #1 NOT #11 so when the userform is open the TextBox in question shows 0
If i correct the #11 to #1 then the TextBox shows 27 of which is the correct value.
Now there will be times when i add to the code below the correct TextBox value will be 0 & will be correct BUT i wish for typos to be shown like ERROR or NOT FOUND as to make it stand out from the 0 value
Rich (BB code):
Private Sub UserForm_Initialize()
Dim ws As Worksheet
Dim lr As Long
Dim rng As Range
Set ws = ActiveSheet
'Find last row with data on column K of sheet
lr = ws.Range("K" & Rows.Count).End(xlUp).Row
'Set range variable
Set rng = ws.Range("A8:K" & lr)
Me.TextBox1 = Application.WorksheetFunction.CountIf(rng, "HONDA MC KEY #11")
Me.TextBox2 = Application.WorksheetFunction.CountIf(rng, "HONDA MC KEY #2")
Me.TextBox3 = Application.WorksheetFunction.CountIf(rng, "HONDA MC KEY #3")
Me.TextBox4 = Application.WorksheetFunction.CountIf(rng, "HONDA MC KEY #4")
Me.TextBox5 = Application.WorksheetFunction.CountIf(rng, "REMOTE FOB 3B UK")
Me.TextBox6 = Application.WorksheetFunction.CountIf(rng, "REMOTE FOB 3B USA")
Me.TextBox7 = Application.WorksheetFunction.CountIf(rng, "YAMAHA YH35")
Me.TextBox8 = Application.WorksheetFunction.CountIf(rng, "BUNDLE")
Me.TextBox9 = Application.WorksheetFunction.CountIf(rng, "BLACK")
Me.TextBox10 = Application.WorksheetFunction.CountIf(rng, "GREY")
Me.TextBox11 = Application.WorksheetFunction.CountIf(rng, "RED")
Me.TextBox12 = Application.WorksheetFunction.CountIf(rng, "CLEAR")
Me.TextBox13 = Application.WorksheetFunction.CountIf(rng, "CLONE CHIP ONLY")
Me.TextBox14 = Application.WorksheetFunction.CountIf(rng, "HISS CABLE")
Me.TextBox15 = Application.WorksheetFunction.CountIf(rng, "HISS CABLE ONLY")
Me.TextBox16 = Application.WorksheetFunction.CountIf(rng, "HONDA HON 39 FURY")
Me.TextBox17 = Application.WorksheetFunction.CountIf(rng, "KAWASAKI KW 16")
Me.TextBox18 = Application.WorksheetFunction.CountIf(rng, "SUZUKI SZ 14")
Me.TextBox19 = Application.WorksheetFunction.CountIf(rng, "VALKYRIE KEY")
Me.CommandButton1.SetFocus
End Sub