#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Subtotal

Can anyone tell me how I can amend the macro below works for cells
containing both values & formulas in the areas

Sub subtotalrange()
'

'
For Each NumRange In Selection.SpecialCells(xlConstants,
xlNumbers).Areas

SumAddr = NumRange.Address(False, False)
NumRange.Offset(NumRange.Count, 1).Resize(1, 1).Formula =
"=SUBTOTAL(9," & SumAddr & ")"

Next NumRange
'
End Sub

Thxs

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Subtotal

Hi Al007,

Try:
'================
Public Sub SubtotalRange()
Dim RngA As Range, RngB As Range
Dim RngBig As Range
Dim NumRange As Range
Dim SumAddr As String
Dim CalcMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

On Error Resume Next
Set RngA = Selection.SpecialCells(xlCellTypeConstants)
Set RngB = Selection.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not RngA Is Nothing Then Set RngBig = RngA

If Not RngB Is Nothing Then
If Not RngBig Is Nothing Then
Set RngBig = Union(RngB, RngBig)
Else
Set RngBig = RngB
End If
End If

If Not RngBig Is Nothing Then
For Each NumRange In RngBig.Areas
SumAddr = NumRange.Address(False, False)
NumRange.Offset(NumRange.Count, 1). _
Resize(1, 1).Formula = _
"=SUBTOTAL(9," & SumAddr & ")"
Next NumRange
End If

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<================

---
Regards,
Norman



"al007" wrote in message
oups.com...
Can anyone tell me how I can amend the macro below works for cells
containing both values & formulas in the areas

Sub subtotalrange()
'

'
For Each NumRange In Selection.SpecialCells(xlConstants,
xlNumbers).Areas

SumAddr = NumRange.Address(False, False)
NumRange.Offset(NumRange.Count, 1).Resize(1, 1).Formula =
"=SUBTOTAL(9," & SumAddr & ")"

Next NumRange
'
End Sub

Thxs



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Subtotal

Hi Normal'
Thxs a lot - the macro is working fine so far - will keep u posted in
case I come across any problem - specially I using it also with an
offset = 0
May many thxs


Norman Jones wrote:
Hi Al007,

Try:
'================
Public Sub SubtotalRange()
Dim RngA As Range, RngB As Range
Dim RngBig As Range
Dim NumRange As Range
Dim SumAddr As String
Dim CalcMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

On Error Resume Next
Set RngA = Selection.SpecialCells(xlCellTypeConstants)
Set RngB = Selection.SpecialCells(xlCellTypeFormulas)
On Error GoTo 0

If Not RngA Is Nothing Then Set RngBig = RngA

If Not RngB Is Nothing Then
If Not RngBig Is Nothing Then
Set RngBig = Union(RngB, RngBig)
Else
Set RngBig = RngB
End If
End If

If Not RngBig Is Nothing Then
For Each NumRange In RngBig.Areas
SumAddr = NumRange.Address(False, False)
NumRange.Offset(NumRange.Count, 1). _
Resize(1, 1).Formula = _
"=SUBTOTAL(9," & SumAddr & ")"
Next NumRange
End If

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<================

---
Regards,
Norman



"al007" wrote in message
oups.com...
Can anyone tell me how I can amend the macro below works for cells
containing both values & formulas in the areas

Sub subtotalrange()
'

'
For Each NumRange In Selection.SpecialCells(xlConstants,
xlNumbers).Areas

SumAddr = NumRange.Address(False, False)
NumRange.Offset(NumRange.Count, 1).Resize(1, 1).Formula =
"=SUBTOTAL(9," & SumAddr & ")"

Next NumRange
'
End Sub

Thxs


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
Subtotal To Include Item Description On Subtotal Line Tickfarmer Excel Discussion (Misc queries) 2 February 23rd 10 07:56 PM
sort macro, subtotal and add lines after subtotal David Excel Discussion (Misc queries) 1 August 29th 09 10:56 AM
pasting to subtotal lines without replacing hidden -non-subtotal l harleydiva67 Excel Discussion (Misc queries) 1 October 12th 06 06:02 PM
Bolding the subtotal lines automaticlly When using the Subtotal fu 06Speed6 New Users to Excel 2 October 5th 06 03:52 PM
Subtotal of Subtotal displays Grand Total in wrong row Thomas Born Excel Worksheet Functions 5 January 6th 05 01:46 PM


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