Trouble with Vlookup in VBA

TurboDieselOne

Board Regular
Joined
Oct 29, 2008
Messages
52
Hi

Have this code when you double click on a cell a little form opens with the contents in a multiline text box. Fine works now i need this text box to look up somthing on the activecells contents using vlookup

example cell contents


ARKWRIGHT ROAD--NW3--60643726--4530856866--213185 03/05/2011

Private Sub Userform_Activate()
TextBox1.Value = ActiveCell & Chr(10) & (Application.WorksheetFunction.VLookup(Left(Right(TextBox1.Value, 21), 6), Notes, 16, False))
End Sub

But would also like to add an if statement that this only applies on the condition the Textbox does not have any CHR10's (1 Line Only)

Thanks

PS this will go a long way in cleaning up a great app
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You could use Instr

Code:
    s = "This is line 1" & Chr(10) & "and this is line 2"
    MsgBox InStr(1, s, Chr(10))

this will return the position CHR(10) is located in the string, if the return value is 0 then there are no CHR(10)

Code:
'''''' Not tested
Private Sub Userform_Activate()
if Not Instr(1, TextBox1.Value, chr(10)) = 0 Then
TextBox1.Value = ActiveCell & Chr(10) & (Application.WorksheetFunction.VLookup(Left(Right(TextBox1.Value, 21), 6), Notes, 16, False))
End If
End Sub
 
Upvote 0
I cant get the vlookup bit working though Get that first and set that in a if then situation ie if no chr(10)'s then Use the vlookup part if not then use the active cell contents the fill TextBox1. The vllokup dont work though The Range for the Vlookup is Sheet2! C2:AB1000 and column 15 for example
 
Upvote 0
This has to work like this

TextBox1 on the Userform = active cell
Then If TextBox1 contains more than 1 line then end else
TextBox1 = the value of the active cell & the value of the Text in a vlookup as below

=Vlookup(LEFT(RIGHT(the Activecell,21),6),15,False)

if (Vlookup(LEFT(RIGHT(the Activecell,21),6),15,False)) has got contents in the cell other wise if not then add the word "No Notes Found" to end of TextBox1

Can you grasp what i'm upto


Many Many thanks
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

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