Application Worksheet

excelenergy

Board Regular
Joined
Jun 7, 2012
Messages
142
I'm trying to get a text box on a user form to look up a value in a combobox on the user form...then populate itself with the value it finds.


I'm trying to use Application.Worksheet

Code:
 Private Sub TextBox1_Change()
With Me
.Reg1 = Application.WorksheetFunction.VLookup(CLng(Me.Reg1), Sheet8.Range("A:E"), 2, 0)
End With
End Sub

Doesn't seem to work. I'm not getting any errors. Just no result in the textbox. Any ideas of a more useful way to do this?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
At the moment that code is looking up the value in Reg1 & then trying to populate itself.
should it be
Code:
 Private Sub TextBox1_Change()
With Me
.TextBox1.Value = Application.WorksheetFunction.VLookup(CLng(.Reg1.Value), Sheet8.Range("A:E"), 2, 0)
End With
End Sub
 
Upvote 0
Hey Fluff,

Thanks for the response. I tried that out. I'm getting an "Unexpected separator error" - I don't think VBE likes the name of my sheet...Its called like Dynamic Drop Down (4)....when vbe errors, that's what its highlighting, the name of the sheet I'm referencing.



At the moment that code is looking up the value in Reg1 & then trying to populate itself.
should it be
Code:
 Private Sub TextBox1_Change()
With Me
.TextBox1.Value = Application.WorksheetFunction.VLookup(CLng(.Reg1.Value), Sheet8.Range("A:E"), 2, 0)
End With
End Sub
 
Upvote 0
Then replace Sheet8 with the name of your sheet
 
Upvote 0
This is it...Its still saying unexpected separator

.TextBox1.Value = Application.WorksheetFunction.VLookup(CLng(.Dynamic Chart Drop Down 00 (2).Range.Value), Dynamic Chart Drop Down 00 (2).Range("A:E"), 2, 0)

Then replace Sheet8 with the name of your sheet
 
Upvote 0
Try
Code:
Private Sub TextBox1_Change()
With Me
.TextBox1.Value = Application.WorksheetFunction.VLookup(CLng(.Reg1.Value), Sheets("Dynamic Chart Drop Down 00 (2)").Range("A:E"), 2, 0)
End With
End Sub
 
Last edited:
Upvote 0
Hey Fluff, sorta thing as originally. No errors this time.

The textbox just isn't populating itself that's all. But as far as errors go, nothing popped up.
 
Upvote 0
What is the value in Reg1?
 
Upvote 0
Try putting the code in the Change event of the combobox rather than the textbox you are trying to populate.
 
Upvote 0
Hey guys,

I rearranged it to the change event.

Error on this line - Script out of range.
With ThisWorkbook.Sheets(Sheet8)



Code:
Private Sub ComboBox3_Change()
 Dim Sheet8 As String
    sheetName = "Sheet8"
    With ThisWorkbook.Sheets(Sheet8)
       'For each name in your range
        For Each cell In .Range("A15:J30000")
           'If the name is the one selected in your combobox
            If (cell = ComboBox1.Text) Then
                'Increment value
                .Range(cell.Address).Offset(0, 1).Value = _
                .Range(cell.Address).Offset(0, 1).Value + TextBox1.Value
            End If
        Next cell
    End With
End Sub



Try putting the code in the Change event of the combobox rather than the textbox you are trying to populate.
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,039
Members
452,542
Latest member
Bricklin

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