Reputation: 87
I am trying use a variable name to define the name of a sheet. The code throws up an error at "Find" in the below code.
Dim z As String
Dim r As String
z = ActiveWorkbook.Name
r = Mid(z, Find("_", z, 1), 30)
ActiveSheet.Name = r
Upvotes: 1
Views: 65
Reputation: 12167
The solution with the worksheet function Find would be
r = Mid(z, WorksheetFunction.Find("_", z, 1) + 1, 30)
Upvotes: 3
Reputation: 5770
It seems that you want the value in r
to contain whatever was in z
after an underscore. If so, try
r = mid(z, instr(1, z, "_") + 1)
Upvotes: 4