A
as mellow as a horse
I'm not a newbie programmer (I usually use C++ or Java), but I am new to
VBA.
I'm trying to write a simple VBA procedure to sum the values in an Excel
worksheet column, but only if the corresponding cell in the next column is
non-zero. The logic of how to do this is not very hard, but VBA is bitching
at me about a type mismatch error. The code I've written is:
Dim rwIndex As Integer
Dim auctionProfit As Currency
Dim currentVal As Currency
auctionProfit = 0
For rwIndex = 5 To 54 ' hard-coded row values will do for now....
If Cells(rwIndex, 10) > 0 Then ' if adjacent cell in next row non-zero
currentVal = Cells(rwIndex, 9).Value
If currentVal > 0 Then auctionProfit = auctionProfit + currentVal
End If
Next rwIndex
MsgBox ("Total Completed Auction Profits = " & CStr(auctionProfit))
It's the 'Cells(rwIndex, .....' bit that VBA doesn't like. If I hard-code a
valid value it'll run OK (but will count one row 50 times of course!).
I tried making rwIndex a variant, but it still doesn't work. What data-type
is used by Cells?
VBA.
I'm trying to write a simple VBA procedure to sum the values in an Excel
worksheet column, but only if the corresponding cell in the next column is
non-zero. The logic of how to do this is not very hard, but VBA is bitching
at me about a type mismatch error. The code I've written is:
Dim rwIndex As Integer
Dim auctionProfit As Currency
Dim currentVal As Currency
auctionProfit = 0
For rwIndex = 5 To 54 ' hard-coded row values will do for now....
If Cells(rwIndex, 10) > 0 Then ' if adjacent cell in next row non-zero
currentVal = Cells(rwIndex, 9).Value
If currentVal > 0 Then auctionProfit = auctionProfit + currentVal
End If
Next rwIndex
MsgBox ("Total Completed Auction Profits = " & CStr(auctionProfit))
It's the 'Cells(rwIndex, .....' bit that VBA doesn't like. If I hard-code a
valid value it'll run OK (but will count one row 50 times of course!).
I tried making rwIndex a variant, but it still doesn't work. What data-type
is used by Cells?