Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Need help regarding ComboBox

Dear All,

I have userform. As soon as the user selects the value from combobox the
another test box lookup the value from certain table & returns the result in
textbox. (Here I used the vlookup function).
The combobox list is having alphanumerical value as well as numerical value.
If user selects the alphanumerical value from combobox, it working fine. But
if user selects the numerical value, it doesn't work.The Vlookup function
fails here.
Any idea?

Codes are he

Private Sub cboPart_Change()
Dim LookupRange As Range
On Error Resume Next
Err.Clear
Set LookupRange = Worksheets("LookupLists").Range("A:I")

If cboPart < "" Then
Me.LblDesc = Application.WorksheetFunction.VLookup _
(Me.cboPart.Value, LookupRange, 3, 0)

If Err.Number < 0 Then
MsgBox "An Error occurred ! Plz. check the Part Code!"
Exit Sub
End If
End If
End Sub
--
Thanks in advance.
Vikram P. Dhemare
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Need help regarding ComboBox

I think you have at least a couple of options.

You could check to see if the part number is numeric:
if isnumeric(Me.cboPart.Value) then
'do the lookup using cdbl(Me.cboPart.Value)

or you could do it twice (untested):

Option Explicit
Private Sub cboPart_Change()
Dim LookupRange As Range
Dim res As Variant

Set LookupRange = Worksheets("LookupLists").Range("A:I")

If cboPart < "" Then
res = Application.VLookup(Me.cboPart.Value, LookupRange, 3, 0)
If IsError(res) Then
'look as a number:
res _
= Application.VLookup(CDbl(Me.cboPart.Value), LookupRange, 3, 0)
End If

If IsError(res) Then
MsgBox "An Error occurred ! Plz. check the Part Code!"
Else
Me.LblDesc = res
End If
End If
End Sub

But I think I would use a third option.

I'd change my table to be text in column A, then just look for text.



Vikram Dhemare wrote:

Dear All,

I have userform. As soon as the user selects the value from combobox the
another test box lookup the value from certain table & returns the result in
textbox. (Here I used the vlookup function).
The combobox list is having alphanumerical value as well as numerical value.
If user selects the alphanumerical value from combobox, it working fine. But
if user selects the numerical value, it doesn't work.The Vlookup function
fails here.
Any idea?

Codes are he

Private Sub cboPart_Change()
Dim LookupRange As Range
On Error Resume Next
Err.Clear
Set LookupRange = Worksheets("LookupLists").Range("A:I")

If cboPart < "" Then
Me.LblDesc = Application.WorksheetFunction.VLookup _
(Me.cboPart.Value, LookupRange, 3, 0)

If Err.Number < 0 Then
MsgBox "An Error occurred ! Plz. check the Part Code!"
Exit Sub
End If
End If
End Sub
--
Thanks in advance.
Vikram P. Dhemare


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Need help regarding ComboBox

Thanks a lot Mr. Dave. Its working (Second option)
Since last 3 weeks I was looking for the solution but couldn't get.
Thanks again.

--
Thanks,
Vikram P. Dhemare


"Dave Peterson" wrote:

I think you have at least a couple of options.

You could check to see if the part number is numeric:
if isnumeric(Me.cboPart.Value) then
'do the lookup using cdbl(Me.cboPart.Value)

or you could do it twice (untested):

Option Explicit
Private Sub cboPart_Change()
Dim LookupRange As Range
Dim res As Variant

Set LookupRange = Worksheets("LookupLists").Range("A:I")

If cboPart < "" Then
res = Application.VLookup(Me.cboPart.Value, LookupRange, 3, 0)
If IsError(res) Then
'look as a number:
res _
= Application.VLookup(CDbl(Me.cboPart.Value), LookupRange, 3, 0)
End If

If IsError(res) Then
MsgBox "An Error occurred ! Plz. check the Part Code!"
Else
Me.LblDesc = res
End If
End If
End Sub

But I think I would use a third option.

I'd change my table to be text in column A, then just look for text.



Vikram Dhemare wrote:

Dear All,

I have userform. As soon as the user selects the value from combobox the
another test box lookup the value from certain table & returns the result in
textbox. (Here I used the vlookup function).
The combobox list is having alphanumerical value as well as numerical value.
If user selects the alphanumerical value from combobox, it working fine. But
if user selects the numerical value, it doesn't work.The Vlookup function
fails here.
Any idea?

Codes are he

Private Sub cboPart_Change()
Dim LookupRange As Range
On Error Resume Next
Err.Clear
Set LookupRange = Worksheets("LookupLists").Range("A:I")

If cboPart < "" Then
Me.LblDesc = Application.WorksheetFunction.VLookup _
(Me.cboPart.Value, LookupRange, 3, 0)

If Err.Number < 0 Then
MsgBox "An Error occurred ! Plz. check the Part Code!"
Exit Sub
End If
End If
End Sub
--
Thanks in advance.
Vikram P. Dhemare


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
Combobox items determined by the selection in another combobox Alerion Excel Programming 2 September 13th 06 01:07 PM
Combobox options based on the input of another combobox afmullane[_5_] Excel Programming 1 May 3rd 06 01:44 PM
ComboBox list reliant on the entry from a different ComboBox ndm berry[_2_] Excel Programming 4 October 4th 05 04:40 PM
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox Minitman[_4_] Excel Programming 3 October 26th 04 07:58 PM


All times are GMT +1. The time now is 03:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"