Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default How to use macro to set "Sum" function

Do anyone know if i want to set a macro which i want to comprise 2 elements:

1: total underline
2: sum ("Sum" function in Excel which automatically sum up all the cells
with figures)

Every time i set, the no. of cells to be added are fixed. for example, Col A
has 3 cells to sum up; when i apply it to Col B which has 5 cells, it also
only add up the last 3 cells, not 5.

Can anyone advise me on this matter?

Thank you so much.


--
New user
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,480
Default How to use macro to set "Sum" function

Hi

Try the following macro.
It assumes you have selected the range of cells you wish to Sum, then run
the macro.

Sub addup()

Dim i As Long, lr As Long, j As Long
Dim rng As String, rng1 As String, rng2 As String
With Selection
i = .Row
j = .Column
lr = .Rows.Count + 1
End With
rng1 = Cells(i, j).Address
rng2 = Cells(lr - 1, j).Address
Cells(lr, j) = "=SUM(" & rng1 & ":" & rng2 & ")"
With Cells(lr, j).Borders(xlEdgeTop)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With

End Sub

--
Regards
Roger Govier

"New user" wrote in message
...
Do anyone know if i want to set a macro which i want to comprise 2
elements:

1: total underline
2: sum ("Sum" function in Excel which automatically sum up all the cells
with figures)

Every time i set, the no. of cells to be added are fixed. for example, Col
A
has 3 cells to sum up; when i apply it to Col B which has 5 cells, it also
only add up the last 3 cells, not 5.

Can anyone advise me on this matter?

Thank you so much.


--
New user


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text "comparison" operator for "contains" used in an "IF" Function Pawaso Excel Worksheet Functions 4 April 4th 23 11:35 AM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"No RETURN() or HALT() function found on macro sheet." Will Excel Worksheet Functions 2 January 4th 07 10:10 PM
Is there a "last saved on date/user" macro/function for Excel 2003 Zliz Excel Discussion (Misc queries) 2 January 2nd 07 10:12 PM
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM


All times are GMT +1. The time now is 12:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"