View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default macro to subtract across columns

Try this. Select the row in question and run the macro

Public Sub test()
Dim tmp As Double
Dim nAmount As Double
Dim iRow As Long
Dim icol As Long
iRow = ActiveCell.Row
nAmount = Cells(iRow, "A").Value
icol = 5
Do While nAmount < 0 And icol 1
tmp = nAmount
nAmount = nAmount + Cells(iRow, icol).Value
Cells(iRow, icol).Value = Application.Max(0, Cells(iRow, icol).Value
+ tmp)
icol = icol - 1
Loop
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



wrote in message
oups.com...
Hello,

I'm trying to automate a method of summing across columns. To be
exact, let's say I have 5 columns (A B C D E), the first of which
MIGHT contain a negative value (it may also contain a positive value,
and B C D E might have a zero or some positive value. What I want to
do is... IF A has a negative value I want it to add it to E (to reduce
it), if E becomes zero and there is still some left from A, I want it
to add the remainder to D... then C.... then B. Essentially I want
the values of E D C B to be reduced, in turn, by the value that is in
A (but only if A has a negative value).

I'm hoping this makes sense... and I'm hoping someone out there can
figure this out.

Cheers.