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

  • Thread starter Thread starter Aus-JN
  • Start date Start date
A

Aus-JN

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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top