Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Rewrite Subtotal Fomula

Hi There,

I would like to replace the cells in "my selection" which contain a
Subtotal-formula
with a new one:

eg:
=SUBTOTAL(9;XXX***:XXX***)
should become
=SUBTOTAL(9;XXX***:Above)

=SUBTOTAL(11;YYY***:YYY***)
should become
=SUBTOTAL(11;YYY***:Above)

Where "Above" is defined name which I create as follows:
ActiveWorkbook.Names.Add Name:="Above", RefersToR1C1:= _
"=INDIRECT(""R[-1]C"",0)"

Thanks for your insight!
Sige

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Rewrite Subtotal Fomula

Sub EFGH()
Dim cell As Range, s As String, s1 As String
Dim iloc As Long
For Each cell In Selection.SpecialCells(xlFormulas)
s = cell.Formula
If InStr(1, s, "Subtotal", vbTextCompare) Then
iloc = InStr(1, s, ":", vbTextCompare)
s1 = Mid(s, iloc + 1, (Len(s) - iloc) - 1)
s = Replace(s, s1, "Above")
cell.Formula = s
End If
Next

End Sub

--
Regards,
Tom Ogilvy


"Sige" wrote:

Hi There,

I would like to replace the cells in "my selection" which contain a
Subtotal-formula
with a new one:

eg:
=SUBTOTAL(9;XXX***:XXX***)
should become
=SUBTOTAL(9;XXX***:Above)

=SUBTOTAL(11;YYY***:YYY***)
should become
=SUBTOTAL(11;YYY***:Above)

Where "Above" is defined name which I create as follows:
ActiveWorkbook.Names.Add Name:="Above", RefersToR1C1:= _
"=INDIRECT(""R[-1]C"",0)"

Thanks for your insight!
Sige


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

Hi Tom,

Thanks a lot!!!

There is still an issue ( or 2 ;-) ) though:
1. If I just select 1 cell ...it works on the whole sheet!
2. If there there is a subtotal working on just 1row, like eg:
=SUBTOTAL(9;E2:E2) then I get:
=SUBTOTAL(9;Above:Above) which normally operates fine!
Though in the bizar case that it I have 2nd, 3rd, 4 th level etc
-subtoals working on 1 row like:

E24: 3000
E25: =SUBTOTAL(9;E24:E24) result 3000
E26: =SUBTOTAL(9;E24:E24) result 3000
E26: =SUBTOTAL(9;E24:E24) result 3000
E27: =SUBTOTAL(9;E24:E24) result 3000

my output does returns:
3000
=SUBTOTAL(9;Above:Above) result 3000
=SUBTOTAL(9;Above:Above) result 0
=SUBTOTAL(9;Above:Above) result 0
=SUBTOTAL(9;Above:Above) result 0

I create these subtotals (1st, 2nd, higher level) automatically. On
rather big lists, in which I unfortunately have too many of these
"exceptions".

Is there a way to resolve this??
Sige

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Rewrite Subtotal Fomula

This does what it should ... honours to Tom though!

Sub ABCD()
Dim cell As Range, s As String, s1 As String
Dim iloc As Long, jloc As Long

ActiveWorkbook.Names.Add Name:="Above", RefersToR1C1:= _
"=INDIRECT(""R[-1]C"",0)"
If Selection.Count = 1 Then
MsgBox "Select a Range with more than 1 Cell to Insert ""Above"" in
Subtotal-formulas"
Exit Sub
End If
For Each cell In Selection.SpecialCells(xlFormulas)
s = cell.Formula
If InStr(1, s, "Subtotal", vbTextCompare) Then
iloc = InStr(1, s, ":", vbTextCompare)

jloc = InStr(1, s, ")", vbTextCompare)

s1 = Mid(s, iloc, (jloc - iloc))
s = Application.Substitute(s, s1, ":Above")
cell.Formula = s
End If
Next

End Sub

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
Rewrite name in new format ALaw Excel Discussion (Misc queries) 4 February 6th 08 04:52 PM
How can I rewrite this using an Array? Fred[_21_] Excel Programming 7 September 13th 05 05:45 PM
How to Rewrite these Code? hce[_18_] Excel Programming 0 September 29th 04 09:33 AM
How to Rewrite these Code? hce[_17_] Excel Programming 1 September 29th 04 04:16 AM
How to Rewrite these Code? hce[_16_] Excel Programming 1 September 29th 04 03:33 AM


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