VLookup from textbox value

Flavien

Board Regular
Joined
Jan 8, 2023
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Hello everybody,

Can someone help me, please?
I don't understand why the vlookup function works if I write the value I am looking for in a cell, but does not work from the textbox. while the figure mentioned is the right one.

Since I'm looking for a number, I used the CDbl function to transform the content of the textbox into a number (at least I think), but it doesn't work.

Thank you for your help.

Have a nice day.

Rich (BB code):
Set zone_recherche_1 = WS3.Range("A:H") 'WS3.Range("Tableau_Extraction_OF")
ws1.Range("E17") = Numéro_OF

'   Inscrire le numéro d'OF dans la textbox1
    UserForm1.TextBox1 = Numéro_OF
    UserForm1.TextBox1.Value = CDbl(UserForm1.TextBox1.Value) 'N° OF

'   Fonction VLookUp "Plan N°"
'On Error GoTo Invalid_NumPlan:

'    Num_Plan = WorksheetFunction.VLookup(ws1.Range("E17"), zone_recherche_1, 4, False)
    Num_Plan = WorksheetFunction.VLookup(UserForm1.TextBox1, zone_recherche_1, 4, False)

Capture.JPG
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try putting the CDbl function right in the VLOOKUP function, on that first argument, so you are converting it right there when you are trying to perform the lookup:
VBA Code:
    Num_Plan = WorksheetFunction.VLookup(CDbl(UserForm1.TextBox1), zone_recherche_1, 4, False)
 
Upvote 0
Solution
Try putting the CDbl function right in the VLOOKUP function, on that first argument, so you are converting it right there when you are trying to perform the lookup:
VBA Code:
    Num_Plan = WorksheetFunction.VLookup(CDbl(UserForm1.TextBox1), zone_recherche_1, 4, False)
Hello Joe4,

Sorry for my late reply. Your solution works perfectly!
Thank you!

Have a nice day.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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