Automatically Inserting An Empty Row

tiwancio

New Member
Joined
Sep 19, 2002
Messages
1
Hey all, new member here.

I have a spread sheet I automatically import data into and sort by
several key columns ( via macro). What I would like to do next is
evaluate one of the columns and automatically insert a row when the
data is different than the cell above it. For example col A is
school grade (ie.. 6th grade, 7th grade) col B is students name, col
C is test score.
First I sort by school grade then by score. I would like to automatically
insert an empty row between the grades to make the groupings stand
out better. Absolute number of rows could vary with every import
instance.

Thanks in advance,

Thom Iwancio
Elgin, SC
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Thom, Welcome to the Board try this sub by Barrie Davidson,I think it will do what you need

Sub Insert_row()
' Written by Barrie Davidson
Dim Number_of_rows As Long
Dim Rowinsert As Integer
Number_of_rows = Range("A65536").End(xlUp).Row
Ans = InputBox("How many rows do you want to insert ?", "Rows", 1)
If IsNumeric(Ans) Then
Rowinsert = CInt(Ans)
Else
MsgBox "Invalid number entered", vbCritical, "Error"
Exit Sub
End If
Range("A2").Select
Do Until Selection.Row = Number_of_rows + 1
If Selection.Value <> Selection.Offset(-1, 0).Value Then
Selection.EntireRow.Resize(Rowinsert).Insert
Number_of_rows = Number_of_rows + Rowinsert
Selection.Offset(Rowinsert + 1, 0).Select
Else
Selection.Offset(1, 0).Select
End If
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,575
Messages
6,120,342
Members
448,956
Latest member
Adamsxl

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