billyshears
Board Regular
- Joined
- Aug 29, 2013
- Messages
- 61
I have a userform with a textbox that I want to reference data from a range in a work sheet. I have this formula but I cant seem to get it to work. Where would I paste this code?
Rich (BB code):
Option Explicit Public Sub LoadDataExample()
'Declare our Result range reference
Dim Result As Range: Set Result = Range("A:A").Find(1, LookIn:=xlValues, Lookat:=xlWhole) 'Search for the value 1 in Column A
If Not Result Is Nothing Then 'If our Result reference is Not Nothing (It's something) then do stuff
'We can load the values into our userform by using the range reference (It's a single cell containing the search term)
TextBox1.Text = Result.Value 'This is the cell that contains our search term (1)
TextBox2.Text = Result.Offset(0, 1).Value 'We offset the value being returned by moving 0 rows up/down and moving 1 column to the right
TextBox3.Text = Result.Offset(0, 2).Value 'We offset the value being returned by moving 0 rows up/down and moving 2 columns to the right
End If End Sub