dim problem when using cell() reference
Aimee,
I may have been mistaken about the row as a variable. It's just not good
practice since Row is already a qualifier.
Anyway, I see a view issues.
When using "Cells([Row],[Column})", the Row and Colunm references should be
numbers or variables that are numbers.
So:
Sheets("Sheet1").Cells(r, F)
Should be:
Sheets("Sheet1").Cells(r, 6)
Also, don't use "Set" for your "total" value.
total = Sheets("Sheet1").Cells(r, 6)
Then when referencing "total" later in the code, remove the ".Value".
So instead of :
total.Value = Cells(row - 1, F) + Cells(row, E)
Use:
total = Cells(r - 1, 6) + Cells(r, 5)
Hope this helps,
Paul
--
"aimee209" wrote in message
...
I changed to just "r" and I'm still seeing the same error message that an
object is required.
"PCLIVE" wrote:
I don't think you can use "row" as a variable. Try just "r".
HTH,
Paul
--
"aimee209" wrote in message
...
I am trying to write codes that will add or subtract a number from a
previous
number, depending on whether or not certain cells are blank. It's an
excel
version of a checkbook: if there's nothing listed in credit, subtract
the
debit and if the debit is blank, add the credit to the previous
balance.
I'm having trouble with the dim part for the total. I don't know what
to
set it as.
I've attached the code I have so far.
Thanks!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim row As Integer
row = 3
Dim total As Long
Do
Set total = Sheets("Sheet1").Cells(row, F)
If Cells(row, D) = 0 Then
If Cells(row, E) = 0 Then
total.Value = 0
Else
total.Value = Cells(row - 1, F) + Cells(row, E)
End If
Else: total.Value = Cells(row - 1, F) - Cells(row, D)
End If
If row < 100 Then
row = row + 1
Else: End
End If
Loop
End Sub
|