Insert row question

Bernard2

New Member
Joined
Jun 15, 2011
Messages
44
If I want to add/insert the name Mary (after each Larry) to the Excel column below, without typing in Mary about 10 or more times, what menu would I use?

Bobby
Doris
Jane
Joe
Larry
Bobby
Doris
Jane
Joe
Larry
Bobby
Doris
Jane
Joe
Larry
Bobby
Doris
Jane
Joe
Larry
Bobby
Doris
Jane
Joe
Larry
Bobby
Doris
Jane
Joe
Larry

<tbody>
</tbody>
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If you don't want to use VBA, here's a "menu" approach that will save some keystrokes.

1. Using the ctrl key, select all the cells that come immediately after each Larry.
2. Release the ctrl key, right-click and choose Insert>Shift cells down.
3. Press F2 key and type: Mary.
4.Hold down ctrl key and press Enter.
 
Upvote 0
Well, I guess, there's no Excel menu I can use?
icon5.png
 
Last edited:
Upvote 0
For those who might be interested in seeing a VBA macro solution, this one will work so long as the final outputted range is less than 65500+ rows...
Code:
Sub AddMaryAfterLarry()
  Dim Arr As Variant
  Arr = Application.Transpose(Range("A1", Cells(Rows.Count, "A").End(xlUp)))
  Arr = Split(Replace(Join(Arr, Chr(1)), "Larry", "Larry" & Chr(1) & "Mary"), Chr(1))
  Range("A1").Resize(UBound(Arr) + 1) = Application.Transpose(Arr)
End Sub
 
Upvote 0
Well, I guess, there's no Excel menu I can use?
Your use of the term menu seems a little unusual in this context. There is no menu item (the menus are those things listed on or above the ribbon at the top of the sheet, or right click as mentioned by JoeMo) that will do this task directly.
Perhaps you mean a formula solution or a macro solution?

Rick has given you a macro solution so here is a formula solution. I have assumed a heading at the top (you could always insert a new row for this if required)
1. Ensure the same heading in B1 as A1
2. Put the formula shown in B2 and copy down until blank cells start appearing
3. Copy the new column of names, select A2 and Paste Special -> Values -> OK
4. Delete column B

Excel Workbook
AB
1ListList
2BobbyBobby
3DorisDoris
4JaneJane
5JoeJoe
6LarryLarry
7BobbyMary
8DorisBobby
9JaneDoris
10JoeJane
11LarryJoe
12BobbyLarry
13DorisMary
14JaneBobby
15JoeDoris
16LarryJane
17BobbyJoe
18DorisLarry
19JaneMary
20JoeBobby
21LarryDoris
22BobbyJane
23DorisJoe
24JaneLarry
25JoeMary
26LarryBobby
27BobbyDoris
28DorisJane
29JaneJoe
30JoeLarry
31LarryMary
32Bobby
33Doris
34Jane
35Joe
36Larry
37Mary
38
39
Insert Mary




Now here is another manual way in case that is of interest
1. Put AutoFilter on column A and filter for the first name in the list (Bobby in this case
2. Now click and drag down to select from the second Bobby to and including the first blank cell below the last Bobby
3. Press F5 -> Special... -> Visible cells only -> OK
4. Without changing the selection, use the AutoFilter drop-down again to 'Select All'
5. On the Home ribbon tab choose 'Insert' drop-down in the 'Cells' group and choose Insert Sheet rows
6. Now select the whole of column A by clicking its heading label
7. F5 -> Special... -> Blanks -> OK
8. Type Mary and confirm with Ctrl+Enter, not just Enter

While I'm at it, here is another macro that you could consider.
This code ..
- Assumes the list starts in A1 (that is no heading). If there is a heading, change the two "A1" references in the code to "A2" (no need to change the "A2" that is already there)
- Doesn't require the hard-coding of the last name (Larry) as it just puts Mary before the list starts repeating, whatever that last name is.

Code:
Sub Insert_Mary()
  With Range("A1", Columns("A").Find(What:=Range("A1").Value, After:=Range("A2"), LookAt:=xlWhole))
    .Cells(.Cells.Count).Value = "Mary"
    .Copy .Resize(.Rows.Count * Application.CountIf(.CurrentRegion, .Cells(2).Value))
  End With
End Sub

A further comment is that you actually asked about "inserting a row" for Mary and the only suggestions in the thread up to here to actually do that (probably important if there is other data in the sheet that needs to stay with its own row) are JoeMo's and the 'maual' one i outlined above. If actual row insertion is required, here is another macro to consider.
Code:
Sub Insert_Mary_v2()
  Dim r As Long
  Dim LastName As String
  
  LastName = Range("A" & Rows.Count).End(xlUp).Value
  Application.ScreenUpdating = False
  For r = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
    If Range("A" & r).Value = LastName Then
      Rows(r + 1).Insert
      Range("A" & r + 1).Value = "Mary"
    End If
  Next r
  Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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