ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro again... (https://www.excelbanter.com/excel-programming/305088-macro-again.html)

debra2468[_3_]

Macro again...
 
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 ??????

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Macro again...
 
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.


--
Regards,
Tom Ogilvy

"debra2468 " wrote in message
...
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 I
WANT TO HAVE A SUM OF THE NEGATIVE VALUES AND POSITIVE VALUES...how do i
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 ???????


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 03:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com