Adding multiple rows and columns with formulas

tyr443

New Member
Joined
Mar 4, 2016
Messages
34
Office Version
  1. 365
Platform
  1. Windows
So I have created a button that will add multiple rows in a user defined location.
These additional rows correspond to columns in the next sheet, so far so good, although I am not sure I have done it in the most efficient way, it does work.

Now I need the newly created columns to each have a formula in that corresponds to their location and the rows, I have been trying it with a Do While loop but no matter what I change it gets stuck in a loading process and I have to alt+ctrl+del to end task in excel.

VBA Code:
    RefRow = rowNum
    RefEx = rowNum + (iCountRows - 1)
    
colLet = Split(Cells(1, RefRow).Address(True, False), "$")(0)
colLet2 = Split(Cells(1, RefEx).Address(True, False), "$")(0)

Worksheets(SheetN).Columns(colLet & ":" & colLet2).Insert Shift:=xlToRight


    
LocFrac = rowNum
Do While Cells(36, LocFrac) < iCountRows
LetFrac = Split(Cells(1, LocFrac).Address(True, False), "$")(0)

Worksheets(SheetN).Cells(36, LetFrac).Formula = "=LEFT('" & SheetP & "'!" & LetFrac & "36,(FIND(""/"",'" & SheetP & "'!" & LetFrac & "36,1)-1))+SUM(" & LetFrac & "5:" & LetFrac & "35)&""/""&VLOOKUP(" & LetFrac & "4,Content!$A$1:$F$50,5,FALSE)"
LocFrac = LocFrac + 1
Loop

This is just the snippet of code that has cause it to stop, I would be happy to give more information if needed.
SheetP = The sheet next to the active sheet.
rowNum = The position number of the corresponding rows
iCountRows = The number of rows being inserted in said position
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,215,584
Messages
6,125,673
Members
449,248
Latest member
wayneho98

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