PC Review


Reply
Thread Tools Rate Thread

Add subtotal formula to empty cells

 
 
transferxxx@gmail.com
Guest
Posts: n/a
 
      19th Jul 2007
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 A120 -
instead of A1:A20
(The macro works fine for a selection of A1:A20 but not A120)

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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      19th Jul 2007
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.

"(E-Mail Removed)" 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 A120 -
> instead of A1:A20
> (The macro works fine for a selection of A1:A20 but not A120)
>
> 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
>
>

 
Reply With Quote
 
transferxxx@gmail.com
Guest
Posts: n/a
 
      19th Jul 2007
On Jul 19, 11:32 am, Joel <J...@discussions.microsoft.com> 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.
>
> "transfer...@gmail.com" 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 A120 -
> > instead of A1:A20
> > (The macro works fine for a selection of A1:A20 but not A120)

>
> > 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

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      19th Jul 2007
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

"(E-Mail Removed)" wrote:

> On Jul 19, 11:32 am, Joel <J...@discussions.microsoft.com> 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.
> >
> > "transfer...@gmail.com" 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 A120 -
> > > instead of A1:A20
> > > (The macro works fine for a selection of A1:A20 but not A120)

> >
> > > 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
>
>

 
Reply With Quote
 
GregR
Guest
Posts: n/a
 
      20th Jul 2007
On Jul 19, 12:06 pm, transfer...@gmail.com wrote:
> On Jul 19, 11:32 am, Joel <J...@discussions.microsoft.com> 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.

>
> > "transfer...@gmail.com" 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 A120 -
> > > instead of A1:A20
> > > (The macro works fine for a selection of A1:A20 but not A120)

>
> > > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula refers to empty cells even when cells contains data Monica Rustogi Microsoft Excel Worksheet Functions 1 25th Feb 2010 06:56 PM
Subtotal of values in cells containing formula KC Microsoft Excel Worksheet Functions 1 25th Nov 2009 01:06 PM
Formula and Empty Cells Brian Microsoft Excel Misc 4 21st Feb 2009 12:34 PM
a formula which calculates empty cells jeff lebowski Microsoft Excel Misc 1 15th Jul 2006 12:29 AM
Subtotal counting formula in cells =?Utf-8?B?amltYXI=?= Microsoft Excel Misc 1 1st Jun 2006 01:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:43 AM.