LikeButtah1
New Member
- Joined
- Apr 17, 2018
- Messages
- 34
I am getting a run time error '9' subscript out of range (in red) and I'm unsure why since it was working and now not working. I obviously changed something but I'm unsure what I did. Any help with this code would be appreciated. Thanks.
Rich (BB code):
Sub DistributeFromBiWeeklyPayroll()
Dim R As Long, LastRow As Long, NextRow As Long, ws As Worksheet
Dim LastNames As Variant, QData As Variant
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
LastNames = Range("B4", Cells(LastRow, "B"))
QData = Range("F4", Cells(LastRow, "F"))
For R = 1 To UBound(LastNames)
Set ws = Sheets(LastNames(R, 1))
NextRow = Application.Max(5, ws.Cells(ws.Rows.Count, "C").End(xlUp).Row) + 1
ws.Cells(NextRow, "C") = QData(R, 1)
Next
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
LastNames = Range("B4", Cells(LastRow, "B"))
QData = Range("N4", Cells(LastRow, "N"))
For R = 1 To UBound(LastNames)
Set ws = Sheets(LastNames(R, 1))
NextRow = Application.Max(5, ws.Cells(ws.Rows.Count, "E").End(xlUp).Row) + 1
ws.Cells(NextRow, "E") = QData(R, 1)
Next
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
LastNames = Range("B4", Cells(LastRow, "B"))
QData = Range("O4", Cells(LastRow, "O"))
For R = 1 To UBound(LastNames)
Set ws = Sheets(LastNames(R, 1))
NextRow = Application.Max(5, ws.Cells(ws.Rows.Count, "J").End(xlUp).Row) + 1
ws.Cells(NextRow, "J") = QData(R, 1)
Next
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
LastNames = Range("B4", Cells(LastRow, "B"))
QData = Range("J4", Cells(LastRow, "J"))
For R = 1 To UBound(LastNames)
Set ws = Sheets(LastNames(R, 1))
NextRow = Application.Max(5, ws.Cells(ws.Rows.Count, "F").End(xlUp).Row) + 1
ws.Cells(NextRow, "F") = QData(R, 1)
Next
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
LastNames = Range("B4", Cells(LastRow, "B"))
QData = Range("K4", Cells(LastRow, "K"))
For R = 1 To UBound(LastNames)
Set ws = Sheets(LastNames(R, 1))
NextRow = Application.Max(5, ws.Cells(ws.Rows.Count, "G").End(xlUp).Row) + 1
ws.Cells(NextRow, "G") = QData(R, 1)
Next
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
LastNames = Range("B4", Cells(LastRow, "B"))
QData = Range("L4", Cells(LastRow, "L"))
For R = 1 To UBound(LastNames)
Set ws = Sheets(LastNames(R, 1))
NextRow = Application.Max(5, ws.Cells(ws.Rows.Count, "H").End(xlUp).Row) + 1
ws.Cells(NextRow, "H") = QData(R, 1)
Next
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
LastNames = Range("B4", Cells(LastRow, "B"))
QData = Range("M4", Cells(LastRow, "M"))
For R = 1 To UBound(LastNames)
Set ws = Sheets(LastNames(R, 1))
NextRow = Application.Max(5, ws.Cells(ws.Rows.Count, "I").End(xlUp).Row) + 1
ws.Cells(NextRow, "I") = QData(R, 1)
Next
Range("A1").Select
End Sub