Userform to show error message as opposed 0 in textbox

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. 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


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
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I haven't tested it but give this a try:

Rich (BB code):
Me.TextBox1 = Application.WorksheetFunction.IfError(Application.WorksheetFunction.CountIf(rng, "HONDA MC KEY #11"), 0)
 
Upvote 0
Just reading that how does it giver me the text of ERROR or NOT FOUND.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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