This macro is falling over at the last hurdle and I just can't work out what is wrong.
The user is asked for one piece of information "Enter the ID Number.
What the macro should do then is go to Wks1 find the ID Number and change some cells as a result. This bit works.
It works fine until it reaches this point
Set Wks2 = Worksheets(strWks)
7 rows from the bottom.
My intention was to capture the the name of another worksheet which is held on the same row as the ID Number on Wks1 and call it strWks.
Then further down the macro set the value of Wks2 to that of strWks so that the macro will then go to that sheet and remove data from the row with the same ID Number.
I get a Time Run Error 9.
It just seems to be the bit at the bottom where I am trying to identify Wks2 using strWks.
All help much appreciated.
Sub Macro01C_Auto_Resign()
Dim Wks1 As Worksheet, Wks2 As Worksheet
Dim strFind As String, rngFound As Range
Dim lngRow As Long, rngUnion As Range, strWks As String
strFind = InputBox("Enter the ID Number")
Set Wks1 = Worksheets("Membership Book")
With Wks1
Set rngFound = .Range("A1:A1000").Find(strFind, LookIn:=xlValues)
If Not rngFound Is Nothing Then
With rngFound
strWks = .Offset(0, 9).Value
lngRow = rngFound.Row
.Offset(0, 13).Value = Format(Date, "dd/mm/yy")
.Offset(0, 16).Value = "No"
End With
Set rngUnion = Application.Union(.Range(.Cells(lngRow, "R"), .Cells(lngRow, "S")), _
.Range(.Cells(lngRow, "U"), .Cells(lngRow, "V")), _
.Range(.Cells(lngRow, "X"), .Cells(lngRow, "Y")), _
.Range(.Cells(lngRow, "AA"), .Cells(lngRow, "AB")), _
.Range(.Cells(lngRow, "AD"), .Cells(lngRow, "AE")))
rngUnion.ClearContents
Else
MsgBox "Value Not Found"
Exit Sub
End If
Set rngFound = Nothing
Set Wks2 = Worksheets(strWks)
Set rngUnion = Nothing
End With
Wks2.Range("C1:C1000").Replace What:=strFind, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Set Wks1 = Nothing
Set Wks2 = Nothing
End Sub
Display More