I am trying to create form to update a table. The goal is to search by Template ID and add a MTR code in the corresponding row. It is a simple form but my VBA is pretty simple to. What I have is based on online samples that I have tried to modify to my data. With that said, not sure if I am missing something simple or if I am going about this entirely wrong.
If anyone can offer some advice it will be greatly appreciated.
Form has only 3 controls, text box "SearchTemplate", text box "Mtr", and a command button "CommandButton1"
My table data begins on row 8 and the column which contains the Template ID is "I", the column congaing the MTR is "J" . The code I have associated with the command button is as follows,
When I run the search it processes but it but returns the "Name does not exist." prompt.
If anyone can offer some advice it will be greatly appreciated.
Form has only 3 controls, text box "SearchTemplate", text box "Mtr", and a command button "CommandButton1"
My table data begins on row 8 and the column which contains the Template ID is "I", the column congaing the MTR is "J" . The code I have associated with the command button is as follows,
Code:
Private Sub CommandButton1_Click()
Dim searchRange As Range
Dim foundCell As Range
Dim mysearch As String
mysearch = Me.SearchTemplate.Value
With ThisWorkbook.Sheets("Sheet2")
Set searchRange = .Range("I8", .Range("I" & .Rows.Count).End(xlUp))
End With
Set foundCell = searchRange.Find(what:=mysearch, Lookat:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not foundCell Is Nothing Then
If foundCell.Offset(0, 1).Value = Me.SearchTemplate.Value Then
foundCell.Offset(0, 2).Value = Me.Mtr.Value
Else
MsgBox "Name does not exist."
End If
Else
MsgBox "ID does not exist."
End If
End Sub
Last edited by a moderator: