Insert X number of rows and insert formula in that rows

Ulisses_Carso

New Member
Joined
Sep 4, 2020
Messages
39
Office Version
  1. 365
Platform
  1. Windows
good mornig, I burning my brain for two days with (i guess it is) a simple macro
I have a sheet with X number of rows, what I need is insert a new row above each existing row, wich I already did, now i need to put a formula in each new row.

imagine this: an array with 20x20 with 0 and 1,

each row have a X number of columns filled, wich dificults a little, because I don't want a formula with a blank cell bellow.
The formula can be anything, "=IF(a2="0";"zero";"one") for example.

VBA Code:
Sub InserLine()
   Dim i As Long
   
   For i = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Cells(i, 1) <> Cells(i - 1, 1) Then Rows(i).Resize(1).Insert
   Next i
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
forgot to say, the only condition for the formula is that it uses the cell bellow as reference

as:
cell value
A1 = Formula (IF A2<>"";"ok";"not ok")
A2 = 1
 
Upvote 0

Forum statistics

Threads
1,214,996
Messages
6,122,636
Members
449,092
Latest member
bsb1122

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