View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
aimee209 aimee209 is offline
external usenet poster
 
Posts: 18
Default dim problem when using cell() reference

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