ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to enter blank row (https://www.excelbanter.com/excel-programming/347454-macro-enter-blank-row.html)

MissyLovesExcel

Macro to enter blank row
 
Similar to "SubTotal" without the subtotal, i'm looking to create a macro
that will search for a change in column info and insert a blank row between.
Can you help?

Norman Jones

Macro to enter blank row
 
Hi Missy,

Try:

'============
Public Sub Tester001()
Dim rng As Range
Dim rcell As Range
Dim i As Long
Const col As String = "A" '<<==== CHANGE

For i = Selection.Rows.Count To 2 Step -1
With Cells(i, col)
If .Value < .Offset(-1).Value Then
.EntireRow.Insert
End If
End With
Next i
End Sub
'<<============

Change the value of the col constant to reflect your column of interest.

---
Regards,
Norman



"MissyLovesExcel" wrote in
message ...
Similar to "SubTotal" without the subtotal, i'm looking to create a macro
that will search for a change in column info and insert a blank row
between.
Can you help?




Norman Jones

Macro to enter blank row
 
Hi Missy,

Deleting two redundant variables and taking the opportunity to toggle Screen
updates, try:

'============
Public Sub Tester001()
Dim i As Long
Const col As String = "A" '<<==== CHANGE

Application.ScreenUpdating = False

For i = Selection.Rows.Count To 2 Step -1
With Cells(i, col)
If .Value < .Offset(-1).Value Then
.EntireRow.Insert
End If
End With
Next i

Application.ScreenUpdating = True

End Sub
'<<============


---
Regards,
Norman


"Norman Jones" wrote in message
...
Hi Missy,

Try:

'============
Public Sub Tester001()
Dim rng As Range
Dim rcell As Range
Dim i As Long
Const col As String = "A" '<<==== CHANGE

For i = Selection.Rows.Count To 2 Step -1
With Cells(i, col)
If .Value < .Offset(-1).Value Then
.EntireRow.Insert
End If
End With
Next i
End Sub
'<<============

Change the value of the col constant to reflect your column of interest.

---
Regards,
Norman



"MissyLovesExcel" wrote in
message ...
Similar to "SubTotal" without the subtotal, i'm looking to create a macro
that will search for a change in column info and insert a blank row
between.
Can you help?







All times are GMT +1. The time now is 03:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com