Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default auto sum macro if data is present above the cell


works like a charm! is there a way to make the totals bold? lik
Selection.Font.Bold = True
or something? thank you again for the help

--
onesain
-----------------------------------------------------------------------
onesaint's Profile: http://www.excelforum.com/member.php...nfo&userid=937
View this thread: http://www.excelforum.com/showthread.php?threadid=27095

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default auto sum macro if data is present above the cell

See added line marked with <<<<<<

Option Explicit

Sub AddTotalFormulas()
Dim FirstTotalRow As Long
Dim FirstValue As Range
Dim FormulaTemplate As String
Dim SearchRange As Range
Dim RowOffset As Long
Dim SumFormula As Range
Dim WordTotal As Range

Const FormulaColumn = 14

FormulaTemplate = "=SUM(R[#]C:R[-1]C)"

With ActiveSheet
Set SearchRange = Intersect(.UsedRange, .Columns(FormulaColumn - 1))
End With

With SearchRange
Set WordTotal = .Find(What:="total", _
LookIn:=xlValues, LookAt:=xlPart, _
After:=.Cells(.Cells.Count), _
SearchDirection:=xlNext, _
MatchCase:=False)

If WordTotal Is Nothing Then
MsgBox "Can't find the word 'total' in column " _
& Chr$(SearchRange.Column + 64) & "!", vbOKOnly
Exit Sub
Else
FirstTotalRow = WordTotal.Row
End If
End With


Do
Set SumFormula = WordTotal.Offset(0, 1)
With SumFormula
Set FirstValue = .Offset(-1, 0) 'correct for 0 or 1 values
If FirstValue.Offset(-1, 0) < "" Then
Set FirstValue = FirstValue.End(xlUp)
End If

RowOffset = FirstValue.Row - .Row
.FormulaR1C1 = Replace(FormulaTemplate, "#", Format$(RowOffset))
.Font.Bold = True '<<<<<<
End With

Set WordTotal = SearchRange.FindNext(After:=WordTotal)

Loop While WordTotal.Row < FirstTotalRow

End Sub

On Fri, 22 Oct 2004 15:02:36 -0500, onesaint
wrote:


works like a charm! is there a way to make the totals bold? like
Selection.Font.Bold = True
or something? thank you again for the help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default auto sum macro if data is present above the cell


What if you are summing up a number of columns- Offset with range? Than
you


Myrna Larson Wrote:
See added line marked with <<<<<<

Option Explicit

Sub AddTotalFormulas()
Dim FirstTotalRow As Long
Dim FirstValue As Range
Dim FormulaTemplate As String
Dim SearchRange As Range
Dim RowOffset As Long
Dim SumFormula As Range
Dim WordTotal As Range

Const FormulaColumn = 14

FormulaTemplate = "=SUM(R[#]C:R[-1]C)"

With ActiveSheet
Set SearchRange = Intersect(.UsedRange, .Columns(FormulaColumn - 1))
End With

With SearchRange
Set WordTotal = .Find(What:="total", _
LookIn:=xlValues, LookAt:=xlPart, _
After:=.Cells(.Cells.Count), _
SearchDirection:=xlNext, _
MatchCase:=False)

If WordTotal Is Nothing Then
MsgBox "Can't find the word 'total' in column " _
& Chr$(SearchRange.Column + 64) & "!", vbOKOnly
Exit Sub
Else
FirstTotalRow = WordTotal.Row
End If
End With


Do
Set SumFormula = WordTotal.Offset(0, 1)
With SumFormula
Set FirstValue = .Offset(-1, 0) 'correct for 0 or 1 values
If FirstValue.Offset(-1, 0) < "" Then
Set FirstValue = FirstValue.End(xlUp)
End If

RowOffset = FirstValue.Row - .Row
.FormulaR1C1 = Replace(FormulaTemplate, "#", Format$(RowOffset))
.Font.Bold = True '<<<<<<
End With

Set WordTotal = SearchRange.FindNext(After:=WordTotal)

Loop While WordTotal.Row < FirstTotalRow

End Sub

On Fri, 22 Oct 2004 15:02:36 -0500, onesaint
wrote:


works like a charm! is there a way to make the totals bold? like
Selection.Font.Bold = True
or something? thank you again for the help


--
y8g5k3
-----------------------------------------------------------------------
y8g5k3m's Profile: http://www.excelforum.com/member.php...fo&userid=2568
View this thread: http://www.excelforum.com/showthread.php?threadid=27095

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
auto sum macro if data is present above the cell onesaint[_6_] Excel Programming 2 October 22nd 04 07:32 PM
auto sum macro if data is present above the cell onesaint[_7_] Excel Programming 0 October 22nd 04 04:40 PM
auto sum macro if data is present above the cell onesaint[_5_] Excel Programming 1 October 22nd 04 12:10 AM
auto sum macro if data is present above the cell onesaint[_4_] Excel Programming 0 October 21st 04 06:29 PM
auto sum macro if data is present above the cell onesaint[_3_] Excel Programming 1 October 20th 04 08:35 PM


All times are GMT +1. The time now is 09:03 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"