Automatically inserting blank lines

Carol45

New Member
Joined
Sep 11, 2009
Messages
3
I have a large document with employees names listed on several lines. Is there a formula or macro that can be written to have excel automatically insert a blank line when a new employee's name appears? For example, Davy Crockett appears for 3 lines, Suzy Jones for 2 lines and then another employee for maybe one line or possibly four lines. Is there a way to get excel to automatically insert a blank line when it comes to a new name?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Excel Workbook
AB
1NamesData
2JohnData1
3JohnData2
4JohnData3
5JohnData4
6JohnData5
7BOBData6
8BOBData7
9BOBData8
10JerryData9
11JerryData10
12JerryData11
13SuzieData12
14SuzieData13
15SandyData14
16SandyData15
17SandyData16
18SandyData17
19SandyData18
20PhilData19
Before
Excel Workbook
AB
1NamesData
2JohnData1
3JohnData2
4JohnData3
5JohnData4
6JohnData5
7
8BOBData6
9BOBData7
10BOBData8
11
12JerryData9
13JerryData10
14JerryData11
15
16SuzieData12
17SuzieData13
18
19SandyData14
20SandyData15
21SandyData16
22SandyData17
23SandyData18
24
25PhilData19
After


Code:
Option explicit

Sub AddBlanks()
'JBeaucaire  (9/11/2009)
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row

    For i = LR To 3 Step -1
        If Cells(i, "A") <> Cells(i - 1, "A") Then _
            Rows(i).Insert xlShiftDown
    Next i

End Sub
 
Upvote 0
Thank you so much for your quick response. I'm not that familiar with creating formulas in Excel so can you explain exactly how this formula is entered. Is it some type of macro or other function?
 
Upvote 0
How to use the macro:

1. Open up your workbook
2. Get into VB Editor (Press Alt+F11)
3. Insert a new module (Insert > Module)
4. Copy and Paste in your code (given above)
5. Get out of VBA (Press Alt+Q)
6. Save your sheet

The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

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