ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to add a blank row when a difference between rows is found (https://www.excelbanter.com/excel-discussion-misc-queries/223500-macro-add-blank-row-when-difference-between-rows-found.html)

Aus-JN

Macro to add a blank row when a difference between rows is found
 
Hi All,

I would like to write a macro which selects a series of rows, sorts them by
a particular column and then adds a row whenever a difference bewteen the
rows for that particular column are found.

I can write the macrow which does the sorting but am struggling with adding
the line. I have googled this and have found many methods but unfortunately
I don't understand them enough to make them work for me - don't know which
variables I need to change etc.

Sheeloo[_3_]

Macro to add a blank row when a difference between rows is found
 
The following macro will insert a blank row above the current row if the
difference between the cell in Col A in the row and the cell above it is
greater than 1

Sub AddRow()
ColumntoCheck = "A"
For i = Cells(Rows.Count, ColumntoCheck).End(xlUp).Row To 2 Step -1
If ((Cells(i, ColumntoCheck) - Cells(i - 1, ColumntoCheck)) 1) Then
Cells(i, "A").EntireRow.Insert
' Cells(i, ColumntoCheck) = Cells(i - 1, ColumntoCheck) + 1
End If
Next i
End Sub

"Aus-JN" wrote:

Hi All,

I would like to write a macro which selects a series of rows, sorts them by
a particular column and then adds a row whenever a difference bewteen the
rows for that particular column are found.

I can write the macrow which does the sorting but am struggling with adding
the line. I have googled this and have found many methods but unfortunately
I don't understand them enough to make them work for me - don't know which
variables I need to change etc.



All times are GMT +1. The time now is 06:29 AM.

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