<!--[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
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