Macro again...

D

debra2468

Cells.Select
Selection.Sort Key1:=Range("K2"), Order1:=xlAscending, Header:=xlYes
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

THE ABOVE CODE PUTS THE VALUES IN THE COLUMN IN ASCENDING ORTDER. NOW
WANT TO HAVE A SUM OF THE NEGATIVE VALUES AND POSITIVE VALUES...how do
do that ?

eg:

-9
-6
-4

-19----------------------total

2
5
7
8

22-------------------------total

i need to insert the totals and make them bold ..
any clue ??????
 
T

Tom Ogilvy

Dim cell as Range, rng as Range, rng1 as Range
for each cell in Range("K1:K200")
if cell.value < 0 and cell.offset(1,0).Value >= 0 then
cell.offset(1,0).EntireRow.Insert
cell.offset(1,0).Formula = "=Sum(K1:" & cell.Address(0,0) & ")"
Cell.offset(1,0).Font.bold = True
exit for
end if
Next
set rng = Cell.Offset(2,0)
set rng1 = cells(rows.count,"K").End(xlup)(2)
rng1.Formula = "=Sum(" & Range(rng,rng1.offset(-1,0)).Address(0,0) & _
")"
rng1.font.bold = True

Untested and may contain typos, but should give you a workable approach.
 

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