Mick Peters
Board Regular
- Joined
- May 18, 2015
- Messages
- 93
Hi I am trying to edit a piece of VBA that is behind my user form. The VBA takes the value that is keyed into Old and searches sheet 1 for that number from this it returns TxtIP and TextTanIP and then places them into the corresponding Txt field on the user form. All works well.
What I now need to do as an extension is to use the same input OLD but to search Sheet 2 (simultaneously) to return a value and place it into another(New) text box on the form (I plan on naming something like Replacement). There may be more than 1 occurrence of the number on sheet 2 so I would prefer it to fetch the last one (Search bottom up not top down). The data I want will be in the cell next to the found item.
So the final result would be
Enter TextBox OLD
Return TxtIP From Sheet 1
Return TxtTranIP From Sheet 1
Return Replacment From Sheet 2
Any help would be appreciated.
Thank you,
Mick.
VBA Code:
Private Sub TxtOld_AfterUpdate()
Dim Old As String
Dim FoundRange As Range
'Dim Row As String
Old = TxtOld.Value
Worksheets("Sheet1").Activate
Set FoundRange = Sheets("Sheet1").Cells.Find(what:=Old, LookIn:=xlFormulas, lookat:=xlWhole)
If FoundRange Is Nothing Then
TxtIP.Text = "Not found"
TxtTranIP.Text = "Not found"
Else
TxtIP.Text = FoundRange.Offset(0, 1).Value
TxtTranIP.Text = FoundRange.Offset(0, 1).Value
TxtRow.Text = FoundRange.Row
TxtMac.Text = FoundRange.Offset(0, 2).Value
Record_Date = Now()
End If
End Sub
What I now need to do as an extension is to use the same input OLD but to search Sheet 2 (simultaneously) to return a value and place it into another(New) text box on the form (I plan on naming something like Replacement). There may be more than 1 occurrence of the number on sheet 2 so I would prefer it to fetch the last one (Search bottom up not top down). The data I want will be in the cell next to the found item.
So the final result would be
Enter TextBox OLD
Return TxtIP From Sheet 1
Return TxtTranIP From Sheet 1
Return Replacment From Sheet 2
Any help would be appreciated.
Thank you,
Mick.