Insert row with specific values in columns after specific text

chaostheory

New Member
Joined
Apr 15, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello guys,
I have an excel with hundres of rows similar to this one:

1618516781657.png


I was trying to find a way to find a specific "text", insert a blank row below it and fill it with specific values that I have set before.

For example: I want to find every row with "2b" and insert a row with specific values: column A: copy upper cell, column B: "new value #1", column C: "new value #2".

So before running this "script" I want to specify that I will get "rty" as "new value #1" and "4d" as "new value #2".

After running this my excel looks like this (inserted rows are green):

1618517187725.png


I was trying to find a solution to this, but every single one was only mentioning adding BLANK row, not filling this row up with specific values that I need.

Can somebody help? I have an excel with hundreds of lines that I need to repair :S

Best regards
 

Attachments

  • 1618517141214.png
    1618517141214.png
    13.5 KB · Views: 16

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
How about this?

Code:
Sub PromptInsert()
 Dim i As Long, lr As Long
 Dim in1 As Variant, in2 As Variant, in3 As Variant
 in1 = InputBox("After which?")
 in2 = InputBox("Value for B column")
 in3 = InputBox("Value for C column")
 
 lr = Worksheets("test").Cells(Rows.Count, "A").End(xlUp).Row
 For i = lr To 1 Step -1
  If Worksheets("test").Cells(i, 3) = in1 Then
  Worksheets("test").Rows(i + 1).Insert Shift:=xlShiftDown
  Worksheets("test").Cells(i + 1, 1) = Worksheets("test").Cells(i, 1).Value
  Worksheets("test").Cells(i + 1, 2) = in2
  Worksheets("test").Cells(i + 1, 3) = in3
  Else
  End If
Next i
End Sub
 
Upvote 0
Solution
Hmm. I used this:

FindCell_PrintPDF.xlsm
ABC
1Aaaa11b
2Abbb2b
3Accc3c
4Bddd9b
5Beee10b
6Bfff11b
7Bggg12b
8Chhh99c
9Cjjj101c
10Ckkk102c
11Cmmm11b
12Dnnn99d
13Dppp100D
test


And picked 11b and inserted aaaaa and bbbbb

FindCell_PrintPDF.xlsm
ABC
1Aaaa11b
2Aaaaaabbbbb
3Abbb2b
4Accc3c
5Bddd9b
6Beee10b
7Bfff11b
8Baaaaabbbbb
9Bggg12b
10Chhh99c
11Cjjj101c
12Ckkk102c
13Cmmm11b
14Caaaaabbbbb
15Dnnn99d
16Dppp100D
test
 
Upvote 0
How about this?

Code:
Sub PromptInsert()
Dim i As Long, lr As Long
Dim in1 As Variant, in2 As Variant, in3 As Variant
in1 = InputBox("After which?")
in2 = InputBox("Value for B column")
in3 = InputBox("Value for C column")

lr = Worksheets("test").Cells(Rows.Count, "A").End(xlUp).Row
For i = lr To 1 Step -1
  If Worksheets("test").Cells(i, 3) = in1 Then
  Worksheets("test").Rows(i + 1).Insert Shift:=xlShiftDown
  Worksheets("test").Cells(i + 1, 1) = Worksheets("test").Cells(i, 1).Value
  Worksheets("test").Cells(i + 1, 2) = in2
  Worksheets("test").Cells(i + 1, 3) = in3
  Else
  End If
Next i
End Sub
Sorry for previous post. I made a mistake with worksheet name. This works perfectly! Thank you.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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