noClueCoding
07-25-2012, 09:21 PM
I got a Run-Time Error 424 Object Required at the subtraction of the range variant values. I can not seem to figure out why. When I debug the indexes into these variants is valid.
Dim ws1Range As Variant
Dim ws2Range As Variant
Dim resultRange As Variant
Dim strRangeToCheck As String
Dim x As Long
Dim y As Long
Dim j As Long
' If you know the data will only be in a smaller range, reduce the size of the ranges below.
strRangeToCheck = "A1:O500"
Set ws1 = Worksheets(1)
Set ws2 = Worksheets(2)
Set result = Worksheets(3)
ws1Range = ws1.Range(strRangeToCheck)
ws2Range = ws2.Range(strRangeToCheck)
resultRange = result.Range(strRangeToCheck)
' Subtract cell values
resultRange(x, j).Value = ws2Range(y, j).Value - resultRange(x, j).Value
' Highlight text depending on value.
If resultRange(x, j).Value <0 Then
resultRange(x, j).Font.ColorIndex = 3
ElseIf resultRange(x, j).Value> 0 Then
resultRange(x, j).Font.ColorIndex = 4
End If
Dim ws1Range As Variant
Dim ws2Range As Variant
Dim resultRange As Variant
Dim strRangeToCheck As String
Dim x As Long
Dim y As Long
Dim j As Long
' If you know the data will only be in a smaller range, reduce the size of the ranges below.
strRangeToCheck = "A1:O500"
Set ws1 = Worksheets(1)
Set ws2 = Worksheets(2)
Set result = Worksheets(3)
ws1Range = ws1.Range(strRangeToCheck)
ws2Range = ws2.Range(strRangeToCheck)
resultRange = result.Range(strRangeToCheck)
' Subtract cell values
resultRange(x, j).Value = ws2Range(y, j).Value - resultRange(x, j).Value
' Highlight text depending on value.
If resultRange(x, j).Value <0 Then
resultRange(x, j).Font.ColorIndex = 3
ElseIf resultRange(x, j).Value> 0 Then
resultRange(x, j).Font.ColorIndex = 4
End If