VBA Vlookup

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
779
Office Version
  1. 365
Hi,

I have Userform with textboxes 16 and 17

how can I use vlookup than when type the G/L code in textbox16 get G/L description which is in sheet named CHART_AC
which have two columns that are A = ACCOUNT NUMBER, B = DESCRIPTION.

Thank you,
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I'd use .Find instead of VLookup

VBA Code:
Private Sub TextBox16_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
'check that what was typed in exists in CHART_AC column A
With Me.TextBox16
    If .Value <> "" Then
        If Sheets("CHART_AC").Range("A:A").Find(.Value, LookIn:=xlValues, Lookat:=xlWhole) Is Nothing Then
            MsgBox "The value entered does not exist"
            'keep focus in textbox16
            Cancel = True
            'highlight what's in the textbox
            .SelStart = 0
            .SelLength = Len(.Text)
        End If
    End If
End With
End Sub

VBA Code:
Private Sub TextBox16_AfterUpdate()
'populate textbox17 according to textbox16
TextBox17 = Sheets("CHART_AC").Range("A:A").Find(TextBox16.Value, LookIn:=xlValues, Lookat:=xlWhole).Offset(, 1).Value
End Sub
 
Upvote 0
Solution
It worked perfectly.

Thank you so much.
I switched the marked solution post as confirmed. For your future questions, please mark the post that answered the question instead of your feedback post to help future readers. Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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