Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Need code to replace part of a range within a formula with a defined name

I have a Sub to create subtotals using an InputBox (see below). The
resulting formula is something like this =Subtotal(9,F27:F32).

I need to incorporate a Defined Name "NextUp" which refers to
=INDIRECT("R[-1]C",0) that will automatically include the row above when a
user inserts a row above the subtotals. The resulting formula would be
=Subtotal(9,F27:NextUp).

I manually replace part of the range now with NextUp but would like to add
it to my Sub.

Thanks for your help.


Sub InsertSubtotal()

On Error Resume Next
Set rng = Application.InputBox("Select the Range to subtotal", Type:=8)
If rng Is Nothing Then
MsgBox "No range selected, exiting . . . "
Exit Sub
End If
On Error GoTo 0

Selection.Formula = "=Subtotal(9," & rng.Address(False, False) & ")"

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Need code to replace part of a range within a formula with a defined name

Sub InsertSubtotal()

On Error Resume Next
Set rng = Application.InputBox("Select the Starting to subtotal", Type:=8)
If rng Is Nothing Then
MsgBox "No range selected, exiting . . . "
Exit Sub
End If
On Error GoTo 0

Selection.Formula = "=Subtotal(9," & rng(1,1).Address(False, False) &
":NextUp)"

End Sub


--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Jeff" wrote in message
...
I have a Sub to create subtotals using an InputBox (see below). The
resulting formula is something like this =Subtotal(9,F27:F32).

I need to incorporate a Defined Name "NextUp" which refers to
=INDIRECT("R[-1]C",0) that will automatically include the row above when a
user inserts a row above the subtotals. The resulting formula would be
=Subtotal(9,F27:NextUp).

I manually replace part of the range now with NextUp but would like to add
it to my Sub.

Thanks for your help.


Sub InsertSubtotal()

On Error Resume Next
Set rng = Application.InputBox("Select the Range to subtotal", Type:=8)
If rng Is Nothing Then
MsgBox "No range selected, exiting . . . "
Exit Sub
End If
On Error GoTo 0

Selection.Formula = "=Subtotal(9," & rng.Address(False, False) & ")"

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Need code to replace part of a range within a formula with a defined name

Perfect. Thanks.



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
defined sheet formula to vb code [email protected] Excel Discussion (Misc queries) 2 November 28th 06 08:02 PM
Q: DDE Link - Replace Part of the Formula Reto Walker Excel Worksheet Functions 0 February 14th 06 04:13 PM
Macro to evaluate a cell and replace one part of the formula John[_114_] Excel Programming 2 January 19th 06 07:31 PM
Formula using a SUM of 3 code-defined cells matpj[_22_] Excel Programming 1 November 10th 05 12:40 PM
Application-Defined or Object-Defined Error on simple code Fid[_2_] Excel Programming 1 July 21st 05 08:30 PM


All times are GMT +1. The time now is 02:24 PM.

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"