R
RompStar
Ok, I have this script that looks in two columns on the same row, and
if the date and name matches, it changes the HR code in the third
column.
It works great and even got the lowercase to work, so it don't matter
how it's entered, but I still would like to make it better and not sure
if I should use the right function ? StrReverse ?
But bascially I wanted it to work in a way so that if
Someone enters in search
Jim Smith
or
Smith Jim
it wouldn't matter I have the case not matter, which is good, but
would like to also make the order not matter, I get a error 13 when I
try to use it, not sure, any help would be appreciated.
Thanks
Option Explicit
Sub changedhrcode()
Dim lastrow, cell, cnt
Dim txtDate As Date
Dim txtName As String
Dim txtDept As String
cnt = 0
lastrow = Range("B65536").End(xlUp).Row
txtDate = InputBox("Enter Date You want the records searched for:",
"Enter Date")
txtName = InputBox("Enter Employee Name to search for:", "Enter Name")
txtDept = InputBox("Enter HR Code to replace old:", "Enter Dept")
For Each cell In Range("B1:B" & lastrow)
If cell.Value = txtDate And LCase(cell.Offset(0, 1).Value) =
LCase(txtName) Then
cell.Offset(0, 2).Value = txtDept
cnt = cnt + 1
End If
Next cell
If cnt > 0 Then
MsgBox "Number of records updated: " & cnt
Else
MsgBox "Info Not Found"
End If
End Sub
if the date and name matches, it changes the HR code in the third
column.
It works great and even got the lowercase to work, so it don't matter
how it's entered, but I still would like to make it better and not sure
if I should use the right function ? StrReverse ?
But bascially I wanted it to work in a way so that if
Someone enters in search
Jim Smith
or
Smith Jim
it wouldn't matter I have the case not matter, which is good, but
would like to also make the order not matter, I get a error 13 when I
try to use it, not sure, any help would be appreciated.
Thanks
Option Explicit
Sub changedhrcode()
Dim lastrow, cell, cnt
Dim txtDate As Date
Dim txtName As String
Dim txtDept As String
cnt = 0
lastrow = Range("B65536").End(xlUp).Row
txtDate = InputBox("Enter Date You want the records searched for:",
"Enter Date")
txtName = InputBox("Enter Employee Name to search for:", "Enter Name")
txtDept = InputBox("Enter HR Code to replace old:", "Enter Dept")
For Each cell In Range("B1:B" & lastrow)
If cell.Value = txtDate And LCase(cell.Offset(0, 1).Value) =
LCase(txtName) Then
cell.Offset(0, 2).Value = txtDept
cnt = cnt + 1
End If
Next cell
If cnt > 0 Then
MsgBox "Number of records updated: " & cnt
Else
MsgBox "Info Not Found"
End If
End Sub