-
Subtracting Values of Range Variants
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.
[vba]
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
[/vba]
-
Take out the .Value parts. The variant doesn't have that property (though a range has).
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules