Passing Value from Sub to Userform textbox

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
626
Office Version
  1. 2016
Platform
  1. Windows
I have a Simple Textbox1, Textbox2, and Textbox3 userform8

I what to be able to pull E1, E2, and a cell value to each textbox from a subroutine and active sheet

In my Macro I have:
VBA Code:
Sub calltxtbx()
Dim E1 As Range
Dim E2 As Range

        Set E1 = Range("A2:A1000").Find(Range("AN2"), LookIn:=xlValues, LOOKAT:=xlWhole)
        Set E2 = Range("A2:A1000").Find(Range("AP2"), LookIn:=xlValues, LOOKAT:=xlWhole)
        UserForm8.Show
End Sub

my Userform8 code below
VBA Code:
Private Sub TextBox1_Change()
TextBox1 = E1.Offset(0, 2) & ", " & E1.Offset(0, 1)
End Sub
Private Sub TextBox2_Change()
TextBox2 = E2.Offset(0, 2) & ", " & E2.Offset(0, 1)
End Sub
Private Sub TextBox3_Change()
TextBox3 = Range("AQ2")
End Sub

However all textbox are blank. Any help is greatly appreciate.
 

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.
Place these at the top of module code... remove from userform code. HTH. Dave
VBA Code:
Public E1 As Range
Public E2 As Range
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,171
Members
452,615
Latest member
bogeys2birdies

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