RicksAtWork
Programmer
I have the following code which is suposed to determine the rank of the cells in defined range:
Private Sub ApplyRankings(targetWorkSheet As Worksheet)
Dim grandTotalRange As Range
Dim grandTotalRangeString As String
'Dim targetCell As CellFormat
Dim lastRow As Integer
lastRow = lngNextRow(targetWorkSheet.Name, 1) - 1
grandTotalRangeString = "U2:U" + CStr(lastRow)
Set grandTotalRange = Range(grandTotalRangeString)
For i = 2 To lastRow
#ERROR HERE
targetWorkSheet.Cells(i, U).Value = Application.WorksheetFunction.Rank(targetWorkSheet.Cells(i, U), grandTotalRange)
Next i
End Sub
I have Highlighted the position the error occurs with #ERROR HERE.
It is an object-defined error.
I think the problem is a result of the manner in which I am selecting the cell.
How should I approach this?
Private Sub ApplyRankings(targetWorkSheet As Worksheet)
Dim grandTotalRange As Range
Dim grandTotalRangeString As String
'Dim targetCell As CellFormat
Dim lastRow As Integer
lastRow = lngNextRow(targetWorkSheet.Name, 1) - 1
grandTotalRangeString = "U2:U" + CStr(lastRow)
Set grandTotalRange = Range(grandTotalRangeString)
For i = 2 To lastRow
#ERROR HERE
targetWorkSheet.Cells(i, U).Value = Application.WorksheetFunction.Rank(targetWorkSheet.Cells(i, U), grandTotalRange)
Next i
End Sub
I have Highlighted the position the error occurs with #ERROR HERE.
It is an object-defined error.
I think the problem is a result of the manner in which I am selecting the cell.
How should I approach this?