Not Sure What To Do

NeedsHelp2

New Member
Joined
Nov 20, 2005
Messages
22
I'm using the code below which works fine if the user selects an item in the combo box. The problem is if they mistype something, it stops the whole procedure. I know the solution is something to do with trapping errors but I don't know how set it up.


Label35.Caption = Application.VLookup(cmbN.Value, Range("SiteName"), 2, False)
 
Sorry about this but am still struggling to get the correct results. Have reduced the number of text boxes to one so that it can be easier to follow.

This part gives the expected result.

If txtQ = Y and cmbG & cmbL are in the lookup the correct answer is given.

If txtQ = "" and cmbG & cmbL are in the lookup the correct answer is given.

This part should make the label read "Not Found"

If txtQ = Y and cmbG & cmbL are not in the lookup then the label does not change to "Not Found"

If txtQ = "" and cmbG & cmbL are not in the lookup then the label does not change to "Not Found"

It's the final part that seems to go wrong. I've shown the code below:

If txtQ.Text = "Y" Then
On Error Resume Next
Label37.Caption = Application.VLookup(cmbG.Value & cmbL.Value, Range("finance"), 2, False)
If Err <> 0 Then
Err.Clear
End If
ElseIf txtQ.Text = "" Then
On Error Resume Next
Label37.Caption = Application.VLookup(cmbG.Value & cmbL.Value, Range("finance"), 4, False)
If Err <> 0 Then
Err.Clear
Label37.Caption = "Not Found"
End If
End If
On Error GoTo 0
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
This worked for me:

Code:
Private Sub CommandButton1_Click()
    On Error Resume Next
    If txtQ.Text = "Y" Then
        Label37.Caption = Application.VLookup(cmbG.Value & cmbL.Value, Range("finance"), 2, False)
        If Err <> 0 Then
            Err.Clear
            Label37.Caption = "Not Found"
        End If
    ElseIf txtQ.Text = "" Then
        Label37.Caption = Application.VLookup(cmbG.Value & cmbL.Value, Range("finance"), 4, False)
        If Err <> 0 Then
            Err.Clear
            Label37.Caption = "Not Found"
        End If
    End If
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,693
Messages
6,126,246
Members
449,304
Latest member
hagia_sofia

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