I am receiving a runtime error 91 for the following code. It occurs at the newrow = Nme.Range("L4:L70").Find(newnme).Row line.
Code:
Private Sub Cmd_Add_Click()
Dim nextrow As Integer
Dim newnme, nxtnme As String
Dim newrow, wkrow As Range
Dim rw, n As Integer
Set Wkly = Sheets("Weekly")
Set Nme = Sheets("Names")
Set Dty = Sheets("AddDuty")
nextrow = Nme.Range("A3").End(xlDown).Row + 1
With Nme
.Range("A" & nextrow).Value = UCase(Txt_LastName)
.Range("B" & nextrow).Value = UCase(Txt_FirstName)
.Range("C" & nextrow).Value = Cbo_Rank
.Range("D" & nextrow).Value = UCase(Cbo_CrewPos)
If Chk_Attch = True Then
.Range("E" & nextrow).Value = "X"
End If
newnme = .Range("L" & nextrow).Value
End With
n = 4
For rw = 5 To 72 Step 2
Wkly.Range("A" & rw).Value = Nme.Range("A" & n) & " " & Left(Nme.Range("B" & n), 1)
Wkly.Range("B" & rw).Value = Nme.Range("D" & n)
n = n + 1
Next rw
If Nme.Range("E" & n) = "X" Then
Nme.Shapes("Txt_Attached").Copy
End If
Nme.Sort.SortFields.Clear
Nme.Sort.SortFields.Add Key:=Range("A4"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With Nme.Sort
.SetRange Range("A4:E70")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Nme.Cells.Font.Superscript = False
newrow = Nme.Range("L4:L70").Find(newnme).Row
nxtnme = Nme.Range("L" & newrow + 1).Value
With Wkly
rw = .Range("A5:A70").Find(what:=nxtnme).Row
wkrow = .Range("A5:A70").Find(what:=newnme).Row
.Rows(rw & ":" & rw + 1).Cut
.Rows(wkrow & ":" & wkrow + 1).Insert Shift:=xlDown
End With
End Sub
Last edited by a moderator: