Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Add subtotal formula to empty cells

Can anybody pls help me to modify this code to make this work with
adjacent column(more than 1 coumn) i.e if my selection is A1:D20 -
instead of A1:A20
(The macro works fine for a selection of A1:A20 but not A1:D20)

Sub addsubtotalrange()
'

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

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

Next NumRange
'
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Add subtotal formula to empty cells

the problem is simple

from:
NumRange.Offset(NumRange.Count, 0).Resize(1, 1).Formula =
to:
NumRange.Offset(NumRange.Rows.Count, 0).

You only want the number of rows, not the total number of cells.

" wrote:

Can anybody pls help me to modify this code to make this work with
adjacent column(more than 1 coumn) i.e if my selection is A1:D20 -
instead of A1:A20
(The macro works fine for a selection of A1:A20 but not A1:D20)

Sub addsubtotalrange()
'

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

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

Next NumRange
'
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Add subtotal formula to empty cells

On Jul 19, 11:32 am, Joel wrote:
the problem is simple

from:
NumRange.Offset(NumRange.Count, 0).Resize(1, 1).Formula =
to:
NumRange.Offset(NumRange.Rows.Count, 0).

You only want the number of rows, not the total number of cells.

" wrote:
Can anybody pls help me to modify this code to make this work with
adjacent column(more than 1 coumn) i.e if my selection is A1:D20 -
instead of A1:A20
(The macro works fine for a selection of A1:A20 but not A1:D20)


Sub addsubtotalrange()
'


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


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


Next NumRange
'
End Sub


It's not good as I don't get the correct result from my formula -
which should subtotal cells in corresponding column only.
pls help

thxs

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Add subtotal formula to empty cells

It wasn't clear if you wanted one total or a seperate total for each column.
Try this

Sub addsubtotalrange()
'
For Each NumRange In _
Selection.SpecialCells(xlConstants, xlNumbers).Areas
For ColCount = 0 To (NumRange.Columns.Count - 1)
SumAddr = NumRange.Offset(0, ColCount). _
Resize(NumRange.Rows.Count, 1).Address(False, False)
NumRange.Offset(NumRange.Rows.Count, ColCount). _
Resize(1, 1).Formula = _
"=SUBTOTAL(9," & SumAddr & ")"
Next ColCount

Next NumRange

" wrote:

On Jul 19, 11:32 am, Joel wrote:
the problem is simple

from:
NumRange.Offset(NumRange.Count, 0).Resize(1, 1).Formula =
to:
NumRange.Offset(NumRange.Rows.Count, 0).

You only want the number of rows, not the total number of cells.

" wrote:
Can anybody pls help me to modify this code to make this work with
adjacent column(more than 1 coumn) i.e if my selection is A1:D20 -
instead of A1:A20
(The macro works fine for a selection of A1:A20 but not A1:D20)


Sub addsubtotalrange()
'


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


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


Next NumRange
'
End Sub


It's not good as I don't get the correct result from my formula -
which should subtotal cells in corresponding column only.
pls help

thxs


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Add subtotal formula to empty cells

On Jul 19, 12:06 pm, wrote:
On Jul 19, 11:32 am, Joel wrote:





the problem is simple


from:
NumRange.Offset(NumRange.Count, 0).Resize(1, 1).Formula =
to:
NumRange.Offset(NumRange.Rows.Count, 0).


You only want the number of rows, not the total number of cells.


" wrote:
Can anybody pls help me to modify this code to make this work with
adjacent column(more than 1 coumn) i.e if my selection is A1:D20 -
instead of A1:A20
(The macro works fine for a selection of A1:A20 but not A1:D20)


Sub addsubtotalrange()
'


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


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


Next NumRange
'
End Sub


It's not good as I don't get the correct result from my formula -
which should subtotal cells in corresponding column only.
pls help

thxs- Hide quoted text -

- Show quoted text -


Your selection should still be A1:A20, but change resize(1,4)

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
Formula refers to empty cells even when cells contains data Monica Rustogi Excel Worksheet Functions 1 February 25th 10 06:56 PM
Subtotal of values in cells containing formula KC Excel Worksheet Functions 1 November 25th 09 01:06 PM
Formula and Empty Cells Brian Excel Discussion (Misc queries) 4 February 21st 09 12:34 PM
Subtotal counting formula in cells jimar Excel Discussion (Misc queries) 1 June 1st 06 01:53 AM
continuing formula when cells are empty Cyrus Excel Worksheet Functions 1 February 17th 06 03:59 PM


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

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

About Us

"It's about Microsoft Excel"