Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Code Lookup for Number

I have the following code for a combobox lookup but it will not find the
value when the combox text is a number:

Private Sub ComboBox1_Click()

Dim nMatch As Long
With ComboBox1
If .Text < "" Then
On Error Resume Next
nMatch = WorksheetFunction.Match(CStr(.Text),
Worksheets("Produced").Range("A3:A500"), 0)
On Error GoTo 0
If nMatch < 0 Then

TextBox1.Text = WorksheetFunction.VLookup(CStr(ComboBox1.Text), Worksheets("
Produced").Range("A3:Z500"), 2, False)

Else
MsgBox "Value Not Found"
.SelLength = Len(.Text)
.SelStart = 0
.SetFocus
Cancel = True
End If
End If
End Sub


Cheers
Greg



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Code Lookup for Number

Gregor,

Try this version

Private Sub ComboBox1_Click()
Dim nMatch As Long
With ComboBox1
If .Text < "" Then
On Error Resume Next
If IsNumeric(.Value) Then
nMatch = WorksheetFunction.Match(CDbl(.Text),
Worksheets("Produced").Range("A3:A500"), 0)
Else
nMatch = WorksheetFunction.Match(.Text,
Worksheets("Produced").Range("A3:A500"), 0)
End If
On Error GoTo 0
If nMatch < 0 Then

If IsNumeric(.Value) Then
TextBox1.Text = WorksheetFunction.VLookup(CDbl(.Value),
_
Worksheets("Produced").Range("A3:Z500"), 2, False)
Else
TextBox1.Text = WorksheetFunction.VLookup(.Value, _
Worksheets("Produced").Range("A3:Z500"), 2, False)
End If
Else
MsgBox "Value Not Found"
.SelLength = Len(.Text)
.SelStart = 0
.SetFocus
Cancel = True
End If
End If
End With
End Sub


--
HTH

-------

Bob Phillips
"gregork" wrote in message
...
I have the following code for a combobox lookup but it will not find the
value when the combox text is a number:

Private Sub ComboBox1_Click()

Dim nMatch As Long
With ComboBox1
If .Text < "" Then
On Error Resume Next
nMatch = WorksheetFunction.Match(CStr(.Text),
Worksheets("Produced").Range("A3:A500"), 0)
On Error GoTo 0
If nMatch < 0 Then

TextBox1.Text = WorksheetFunction.VLookup(CStr(ComboBox1.Text),

Worksheets("
Produced").Range("A3:Z500"), 2, False)

Else
MsgBox "Value Not Found"
.SelLength = Len(.Text)
.SelStart = 0
.SetFocus
Cancel = True
End If
End If
End Sub


Cheers
Greg





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Code Lookup for Number

Many thanks Bob....working well.

Regards
Gregor

"Bob Phillips" wrote in message
...
Gregor,

Try this version

Private Sub ComboBox1_Click()
Dim nMatch As Long
With ComboBox1
If .Text < "" Then
On Error Resume Next
If IsNumeric(.Value) Then
nMatch = WorksheetFunction.Match(CDbl(.Text),
Worksheets("Produced").Range("A3:A500"), 0)
Else
nMatch = WorksheetFunction.Match(.Text,
Worksheets("Produced").Range("A3:A500"), 0)
End If
On Error GoTo 0
If nMatch < 0 Then

If IsNumeric(.Value) Then
TextBox1.Text =

WorksheetFunction.VLookup(CDbl(.Value),
_
Worksheets("Produced").Range("A3:Z500"), 2, False)
Else
TextBox1.Text = WorksheetFunction.VLookup(.Value, _
Worksheets("Produced").Range("A3:Z500"), 2, False)
End If
Else
MsgBox "Value Not Found"
.SelLength = Len(.Text)
.SelStart = 0
.SetFocus
Cancel = True
End If
End If
End With
End Sub


--
HTH

-------

Bob Phillips
"gregork" wrote in message
...
I have the following code for a combobox lookup but it will not find the
value when the combox text is a number:

Private Sub ComboBox1_Click()

Dim nMatch As Long
With ComboBox1
If .Text < "" Then
On Error Resume Next
nMatch = WorksheetFunction.Match(CStr(.Text),
Worksheets("Produced").Range("A3:A500"), 0)
On Error GoTo 0
If nMatch < 0 Then

TextBox1.Text = WorksheetFunction.VLookup(CStr(ComboBox1.Text),

Worksheets("
Produced").Range("A3:Z500"), 2, False)

Else
MsgBox "Value Not Found"
.SelLength = Len(.Text)
.SelStart = 0
.SetFocus
Cancel = True
End If
End If
End Sub


Cheers
Greg







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
Convert a Number Code to a Text Code Traye Excel Discussion (Misc queries) 3 April 6th 07 09:54 PM
Post code lookup Paul Williams Excel Worksheet Functions 5 November 23rd 06 08:25 PM
Zip Code Lookup Add-in GoFigure Excel Discussion (Misc queries) 12 February 20th 06 08:36 PM
vba code for lookup worksheet function Binoy[_2_] Excel Programming 1 December 13th 03 07:47 PM
code for lookup,& triggers. derek Excel Programming 3 July 22nd 03 05:04 AM


All times are GMT +1. The time now is 05:40 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"