LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to add rows(cells) to a named range

Based on your stated need, after sorting on these fields, you could get the
grouping/sum using the built in Data=Subtotal function (turn on the macro
recorder while you do it manually to get the code).

Once you have the subtotals miplaced, you could loop through the subtotal
cells and make a decision on whether it is equal to zero or not. Then you
could delete the rows above by using the directpredent property of the cell
containing the subtotal.

--
Regards,
Tom Ogilvy


"Ctech" wrote in
message ...

Im getting closer, however I'm not there yet.. as After one run throught
the "Do", is goes off track.

ANyone see the problem?


Sub DeleteSumTotalZero()
'
' Macro1 Macro
' Macro recorded 04/10/2005 by Taylor Nelson Sofres plc
'

'

Dim DelRg As Range
Dim Cell As Range
Dim Numb As Long

Dim Output As String
Dim RangeX As Range
Dim sName As String
Set RangeX = Nothing


Numb = 0
' Selects the first cell in the cost centre column

Range("H3").Select



' Add next row to range if it is the same CC and suppliers as the row
above


Do

If ActiveCell.Value = ActiveCell.Offset(-1, 0).Value _
And ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(-1, 1).Value
Then

ActiveCell.Offset(0, 1).Select
With Selection.Interior
ColorIndex = 3
Pattern = xlSolid
End With
ActiveCell.Offset(0, -1).Select
Numb = Numb + 1
ActiveCell.Offset(0, 3) = Numb
ActiveCell.Offset(1, 0).Select

Else


Address = ActiveCell.Offset("-" & Numb, 2).Address
AddressAbove = ActiveCell.Offset(-1, 2).Address


Range(Address, AddressAbove).Select

sName = "'" & ActiveSheet.Name & "'!"

Output = Selection.Address( _
External:=False, RowAbsolute:=False, _
ColumnAbsolute:=False) & ")"

Output = Replace(Output, ",", "," & sName)

Output = "=sum(" & sName & Output

ActiveCell.Offset(0, 1) = Output
ActiveCell.Offset(0, 1).Select
AddresseY = ActiveCell.Address





If ActiveCell.Value = 0 Then
ActiveCell.Offset(Numb, -3).Select
Numb = 0
ActiveCell.Offset(1, 0).Select
Else

ActiveCell.Offset(Numb, 0).Select
With Selection.Interior
ColorIndex = 4
Pattern = xlSolid
End With
Numb = 0

End If



End If




Loop Until IsEmpty(ActiveCell) And IsEmpty(ActiveCell.Offset(0, 1))

Range("H2").Select
TheEnd:
MsgBox ("All Suppliers under Cost centres which adds up to 0 is now
deleted.")


End Sub


--
Ctech
------------------------------------------------------------------------
Ctech's Profile:

http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=473291





 
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
How do I specify column for named range of rows hmm Charts and Charting in Excel 0 July 23rd 07 01:38 PM
Array as a "named range" - formula ok in cells, but error as "named range" tskogstrom Excel Discussion (Misc queries) 11 December 28th 06 04:44 PM
Number of Rows & Columns in a Named Range Michael Excel Dude Excel Discussion (Misc queries) 0 September 3rd 06 11:05 PM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
newbie: manipulating cols & rows in named range DavidH[_2_] Excel Programming 3 July 27th 05 06:36 AM


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