Insterting blank rows

steve-m

New Member
Joined
Jul 6, 2011
Messages
5
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]--> Hi Everyone,


I’m in the process of writing my fist macro and I require some help solving the problem of adding three bank rows into my sheet

Details
The data in my sheet has zero values in cells, when a zero value occurs the rows are moved to the bottom of sheet I have this working I need help with a piece of code to insert three blank rows before the first zero line row. the data in the report will be variable



Thanks
Steve


My macro ends like this

'Move the 0 rows to bottom
Set myRng = Range("A1:AN1").CurrentRegion 'adjust A1 to suit
FirstRow = myRng.Row
lastrow = FirstRow + myRng.Rows.Count - 1
For rw = lastrow To FirstRow Step -1
If Cells(rw, "R") = 0 Then
Rows(rw).Cut Cells(Rows.Count, "A").End(xlUp).Offset(1)
Rows(rw).Delete Shift:=xlUp
'Selection.Insert Shift:=xlDown
End If
Next rw
'Sort the bottom rows:
'First find the first 0 in column R
i = lastrow
Do Until Cells(i, "R") <> 0
i = i - 1
Loop
'Then sort if required
If lastrow - i > 1 Then 'sort required
Set RngToSort = Range(Rows(i + 1), Rows(lastrow))
RngToSort.Sort Key1:=RngToSort.Cells(1, "H"), Order1:=xlAscending, Key2:=RngToSort.Cells(1, "R" _
), Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers, _
DataOption2:=xlSortNormal
End If
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top