help with StrReverse function

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
 
H

Harlan Grove

RompStar wrote...
....
But bascially I wanted it to work in a way so that if

Someone enters in search

Jim Smith
or
Smith Jim
....

Bad idea. What if each of the following were names (first last) of
employees?

Hunter Thomas
Thomas Hunter
Parker Jordan
Jordan Parker
Kim Lee
Lee Kim

How would you handle false matches? Better to stick with normal
conventions - first middle last (spaces only between names) and last,
first middle (comma immediately after last name when it's first).

As for your macro code, there's no StrReverse in it, and it runs just
fine for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top