View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Cliff Carson Cliff Carson is offline
external usenet poster
 
Posts: 5
Default subtotal with vba(urgent)

Ramana,
I won't debate with you in a newsgroup so this is my last post. Your code
is fragile and breaks easily. Try a case in which all the S7 entries are
not contiguous and/or all the S14 entries are not contiguous. Maybe you
think the data won't be provided that way but if your code has any value it
may outlast you and when someone else makes a change to the input your
output will be broken. This is why I said putting formulas into the sheet
was bad design - it can't be adapted to the simple change in the input that
I specified. Want another problem - what's the behavior if there is an
error generating the input and S4 values are generated rather than S14? Are
you satisfied that your output ignores this issue? I am not saying that my
solution is finished or is perfect but it's less likely to easily fall
apart. BTW, I have no idea what you mean by my solution being static.

C

"ramse" wrote in
message ...

Hi Cliff,

Intially Thanks for code.

Hey cliff you know what is meaning of forum it means sharing of
knowldge. ok. If somebody is in trouble we have to share knowledge,
better not give the lectures and unnecessary advices, better learn how
to help others otherwise keep quite . If u don't want to share better
out from the forum.

I'm very busy with my other tasks thats why i posted my question.time
doen't permit me to do this.ok.

But it doesn't work for me. Its static . I'm able to solve my problem.

If you want you can use for yourself also.

Sub ff()

Dim i, j As Long
Dim startrw As Long
Dim erow As Integer

i = 3
j = 2
startrw = 2

Do While Cells(j, 1) < ""
erow = erow + 1
j = j + 1
Loop

Do While Cells(i - 1, 1) < ""
If Cells(i - 1, 1).Value < Cells(i, 1).Value Then
If Cells(erow + 3, 2) < "" Then
erow = erow + 2
End If
Range(Cells(erow + 3, 2), Cells(erow + 3, 4)).Formula =
"=Sum(b" & startrw & _
":b" & i - 1 & ")"
startrw = i
End If
i = i + 1
Loop

End Sub


Thanks,
Ramse.
Cliff Carson Wrote:
Ramana,
You seem desperate and maybe I'm feeling foolish today so I'm giving
you the
code. If this is part of an independent learning experience or you are
a
student, then I've done a good deed. However if you have a job and
need
this to please your boss then I feel I've done you a disservice. You
should
really tell your boss that you don't know how to solve the problem and
that
he should anticipate "urgent" situations better and either provide
more
training for you or find someone else with the right skills. There's
no use
in setting false expectations.

My solution assumes your data matrix starts at the upper left cell and
is
terminated by a blank row. Also, I think your solution of trying to
stick
formulas into the worksheet was the wrong approach. Hopefully you'll
be
able to understand this code sufficiently to see that I took a
different
approach.



--
ramse
------------------------------------------------------------------------
ramse's Profile:

http://www.excelforum.com/member.php...o&userid=31544
View this thread: http://www.excelforum.com/showthread...hreadid=512404