I always get an error everytime I enter not on the combo box

jhazziejhazz

New Member
Joined
Mar 11, 2021
Messages
28
Office Version
  1. 2016
Platform
  1. Windows
I have this entry form and it has a combobox everytime I accidentally press any letters on the keyboard, an error always occurs.

Also can you guys suggest on what should be done, say in these form I have data like RR NO, INVOICE, INVOICE DATE ORDER TYPE that are repetitive, but I need to be present in the form or in the excel file.

I really have no idea what to do in order to save time manually inputting those data,

The overview is that every 1 invoice there are several items in it.

Thank you in advance, you guys are all amazing.

Jhazzie



Please help.
12.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
post the combobox_change sub from the userform
 
Upvote 0
post the combobox_change sub from the userform
Hi,

Here's the code. Thank you.

Private Sub cmbPartNo_Change()

Dim SH As Worksheet
Set SH = ThisWorkbook.Sheets("Product_Masterlist")

Dim i As Integer

If Me.cmbPartNo.Value = "" Then
Else

Me.txt_Description.Value = Application.WorksheetFunction.VLookup(Me.cmbPartNo, SH.Range("B:D"), 2, 0)
Me.txt_Cost.Value = Application.WorksheetFunction.VLookup(Me.cmbPartNo, SH.Range("B:D"), 3, 0)

On Error Resume Next

End If


End Sub
 
Upvote 0
try change this
VBA Code:
If Me.cmbPartNo.Value = "" Then
to this
VBA Code:
If Me.cmbPartNo.ListIndex>-1 Then
 
Upvote 0
VBA Code:
If Me.cmbPartNo.ListIndex > -1 Then
    Me.txt_Description.Value = Application.WorksheetFunction.VLookup(Me.cmbPartNo, SH.Range("B:D"), 2, 0)
    Me.txt_Cost.Value = Application.WorksheetFunction.VLookup(Me.cmbPartNo, SH.Range("B:D"), 3, 0)
    On Error Resume Next
End If

you write your if statements with negative logic
 
Upvote 0
Solution
VBA Code:
If Me.cmbPartNo.ListIndex > -1 Then
    Me.txt_Description.Value = Application.WorksheetFunction.VLookup(Me.cmbPartNo, SH.Range("B:D"), 2, 0)
    Me.txt_Cost.Value = Application.WorksheetFunction.VLookup(Me.cmbPartNo, SH.Range("B:D"), 3, 0)
    On Error Resume Next
End If

you write your if statements with negative logic
Hi diddi,
I have copied your code and its working.
Thank you,

Sorry for my ignorance, but when you say negative logic, what does that exactly mean., I am new to this.

Thank you so much for your help.

Jhazz
 
Upvote 0
the way you write an if statement is like this:
"If the door is closed, then dont do anything, but otherwise you can come in"
Rather than
"If the door is open come in"
 
Upvote 0
the way you write an if statement is like this:
"If the door is closed, then dont do anything, but otherwise you can come in"
Rather than
"If the door is open come in"
I see.

Thank you diddi for your time and for helping me solve this error.

Jhazzie
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

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