I have tried looking through Stack Overflow for previous suggestions but haven't found any that have worked.
Here is my situation: I am trying to look at a simple Excel sheet which shows someone's name, position, and then their "Role" which is a custom field I am creating. Right now, I am looking to just do "Engineers" but will also expand to things like "Admin Assistant" and "Manager". (The real spreadsheet is about 8100 lines long).
Here is an example of some test data:
All I need is to scan through the "Title" column, see if it matches a String (in this case, my test string is engineer), and then to copy the String and the remaining I or II or III or in some cases, IV after it.
I have heard about using a regular expression and have used them in SQL before, but am struggling coming up with what I need. Here is my current code where I tried using the MID function:
Sub GetRole()
' Custom function written to take role out of official title
strRole = "Engineer" ' String to check for
Dim lrow As Integer ' Number of Rows
Dim Role As String ' Role to write into adjacent cell
lrow = Cells(Rows.Count, "B").End(xlUp).Row
For i = lrow To 2 Step -1
If InStr(1, Cells(i, 2), "Engineer") > 0 Then
Role = Mid(Cells(i,3)), 1, 5)
Cells.(i, 3).Value = Role
End If
Next i
End Sub
But that didn't quite work. Any help or advice would be greatly appreciated. I am willing to provide any extra information necessary.