On error equals blank

victorel21

New Member
Joined
Jul 8, 2021
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi, I am making an organizer file for cycle count selection in the company I work for, right now im stuck in this piece of code I want that if the cells find formula below gives error because it was not found that the textbox results in blank.

Private Sub ComboBox1_Change()

Dim x

x = Form4.ComboBox1

Sheets("Classification").Activate

With Sheets("Classification")

On Error Resume Next
Form4.TextBox2 = Cells(.Range("C:C").Find(x, Lookat:=xlWhole).row, 4)

End With

With WorksheetFunction

Form4.TextBox3 = Format(.CountIfs(Sheets("Classification").Range("C:C"), x), "#,##0.00")
Form4.TextBox4 = Format(.SumIfs(Sheets("Classification").Range("G:G"), Sheets("Classification").Range("C:C"), x), "#,##0.00")
Form4.TextBox5 = Format(.SumIfs(Sheets("Classification").Range("H:H"), Sheets("Classification").Range("C:C"), x), "#,##0.00")

End With

End Sub

I have tried various error handling methods but none seem to work, the code should run normally with the exception textbox should be = to blank. Any help is appreciated. Thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about
VBA Code:
Private Sub ComboBox1_Change()

Dim x
Dim Fnd As Range
x = Form4.ComboBox1

Sheets("Classification").Activate

With Sheets("Classification")

Set Fnd = .Range("C:C").Find(x, Lookat:=xlWhole)

End With
If Not Fnd Is Nothing Then
   Form4.TextBox2 = Fnd.Offset(, 4).Value
End If
With WorksheetFunction

Form4.TextBox3 = Format(.CountIfs(Sheets("Classification").Range("C:C"), x), "#,##0.00")
Form4.TextBox4 = Format(.SumIfs(Sheets("Classification").Range("G:G"), Sheets("Classification").Range("C:C"), x), "#,##0.00")
Form4.TextBox5 = Format(.SumIfs(Sheets("Classification").Range("H:H"), Sheets("Classification").Range("C:C"), x), "#,##0.00")

End With

End Sub
 
Upvote 0
How about
VBA Code:
Private Sub ComboBox1_Change()

Dim x
Dim Fnd As Range
x = Form4.ComboBox1

Sheets("Classification").Activate

With Sheets("Classification")

Set Fnd = .Range("C:C").Find(x, Lookat:=xlWhole)

End With
If Not Fnd Is Nothing Then
   Form4.TextBox2 = Fnd.Offset(, 4).Value
End If
With WorksheetFunction

Form4.TextBox3 = Format(.CountIfs(Sheets("Classification").Range("C:C"), x), "#,##0.00")
Form4.TextBox4 = Format(.SumIfs(Sheets("Classification").Range("G:G"), Sheets("Classification").Range("C:C"), x), "#,##0.00")
Form4.TextBox5 = Format(.SumIfs(Sheets("Classification").Range("H:H"), Sheets("Classification").Range("C:C"), x), "#,##0.00")

End With

End Sub

This worked great! Would have never come up with this without your help thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,994
Messages
6,122,633
Members
449,092
Latest member
bsb1122

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