N323100
N323100

Reputation: 43

I cant able to pull the information from the main source

I created a userform that will autofill in all the information using the ID# but I cant pull the source from the specific folder, workbook and range.

Here is my code:

Private Sub TextBox4_Change()
Dim rSource As Range





    If Not r Is Nothing Then
         '// Get value in cell r.row, column 2 into textbox2
       TextBox2.Text = Sheet1.Cells(r.Row, 4).Value
       ComboBox3.Value = Sheet1.Cells(r.Row, 6).Value
       ComboBox4.Value = Sheet1.Cells(r.Row, 8).Value
       ComboBox5.Value = Sheet1.Cells(r.Row, 9).Value

    End If
End sub

Thank you!

Upvotes: 0

Views: 47

Answers (1)

Shai Rado
Shai Rado

Reputation: 33672

See my answer in the code below (explanation inside the code as comments):

Option Explicit

Private Sub TextBox4_Change()

Dim wb As Workbook
Dim rSource As Range

' === first set the Workbook object ===
' if the workbook (Excel file) is already open >> use the line below
Set wb = Workbooks("Request ID.xlsm")

' if its close, then use the alternative line below
Set wb = Workbooks.Open("\\Path\")
' now use the Find function    
Set rSource = wb.Worksheets("Sheet1").Range("A:A").Find(What:=TextBox4.Text, LookAt:=xlWhole, MatchCase:=False)
If Not rSource Is Nothing Then '<-- you need to use the same Range variable you used for the Find
     '// Get value in cell r.row, column 2 into textbox2
   TextBox2.Text = Sheet1.Cells(rSource.Row, 4).Value
   ComboBox3.Value = Sheet1.Cells(rSource.Row, 6).Value
   ComboBox4.Value = Sheet1.Cells(rSource.Row, 8).Value
   ComboBox5.Value = Sheet1.Cells(rSource.Row, 9).Value
End If

End Sub

Upvotes: 1

Related Questions