View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default Insert Blank Row Below Sub-Total?

Miss J,
Yes, I do. Sometimes the first version I write even works.
Select a column in the sub-totaled data and run the code below.
Each row in the selected column, that is blank, will have a row inserted above it.
You will not be able to undo the code or remove sub-totals after running the code.
Having a backup copy of the workbook or worksheet is advised.

'--Code starts here--
Sub AddRowsBelowSubtotal()
Dim rng As Range
Dim N As Long
Dim M As Long
Set rng = Selection.Columns(1)
If rng.Cells.Count = 1 Then
MsgBox "Select more than one cell. ", _
vbExclamation, "Blame Jim Cone"
Exit Sub
End If
Set rng = Application.Intersect(ActiveSheet.UsedRange, rng)
Set rng = rng.SpecialCells(xlCellTypeBlanks)
Application.ScreenUpdating = False
M = rng.Areas.Count
For N = M To 1 Step -1
rng.Areas(N).Rows(1).EntireRow.Insert shift:=xlDown
Next
Application.ScreenUpdating = True
MsgBox M & " rows were inserted. ", , "Blame Jim Cone"
Set rng = Nothing
End Sub
'-- Code ends here--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Miss Jenny"
wrote in message
I don't know how to write the VBA code. Do you?
--
Miss Jenny



"Jim Cone" wrote:
You can do it with only one insert command.
But you have to select a single cell in the row below each sub-total line.
Hold the Ctrl key down as you select each cell.
Then on the Insert menu choose 'Rows'.

Also, some VBA code could do it.
--
Jim Cone
Portland, Oregon USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Miss Jenny"

wrote in message
Is there a more efficient way to insert a blank row after each sub-total line
other than to manually insert each one?
--
Miss Jenny