Application-defined or object-defined error Please Help

S

sastry.m.s

i am getting this error while running this code wahts wrong please help

Sub Loop8()

Range("D1").Select
Do
If IsEmpty(ActiveCell.Offset(0, -1)) Then
ActiveCell.Value = 0
ActiveCell.Offset(0, -1).Value = "Customer"
ElseIf ActiveCell.Offset(0, -1).Value = ActiveCell.Offset(-1,
-1).Value Then
ActiveCell.Value = 0
Else
ActiveCell.Value = ActiveCell.Offset(0, -2).Value -
ActiveCell.Offset(0, -3).Value
End If
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))



End Sub
 
P

paul.robinson

Hi
You start in D1 but further down the code you have
ActiveCell.Offset(-1,-1) which is ABOVE the first row?! Do you mean
offset(1, -1) or maybe you need to start in D2?

regards
Paul
 
G

Guest

If C1 isn't empty, then the next statement executed in your IF sequence is

ElseIf ActiveCell.Offset(0, -1).Value = ActiveCell.Offset(-1, -1).Value Then

Since that line tries to look at C0, which doesn't exist, you get that error.
 
S

sastry.m.s

Exactly guys Thanks a lot i resolved it with
Sub Loop8()
' This loop does the calculating itself and writes the result into each
cell
Range("D1").Select
Do

If IsEmpty(ActiveCell.Offset(0, -1)) Then
ActiveCell.Value = 0
ActiveCell.Offset(0, -1).Value = "Customer"

ElseIf ActiveCell.Row = "1" Then
ActiveCell.Value = ActiveCell.Offset(0, -2).Value -
ActiveCell.Offset(0, -3).Value


ElseIf ActiveCell.Offset(0, -1).Value = ActiveCell.Offset(-1, -1)
Then
ActiveCell.Value = 0

Else
ActiveCell.Value = ActiveCell.Offset(0, -2).Value -
ActiveCell.Offset(-1, -2).Value
End If
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, -2))



End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top