Insert formula into cells with variable range

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi All,
Thanks again for your excecllent help in the past. I have a data export function that finds a dynamic range, copies the values and inserts into a new worksheet. This part is working well.

What I need it to do next is to insert two columns before the imported data and add a simple formula (e.g. "=range("C2")" or similar) to each cell in the added columns.

thanks in advance!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Possibly

Code:
Sub InsCols()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("A:B").Insert
Range("A1:B" & LR).Formula = "=$C1"
End Sub
 
Upvote 0
Thanks Peter. Perhaps I wasn't clear enough with my question. I need all of the cells between let's say row 3 and the last row to have an identical formula. The code you kindly posted puts the formula only on the last row.
 
Upvote 0
Sorry, I modified it for my specific spreadsheet, and I had a typo. It's working great, thanks again.
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,932
Members
449,480
Latest member
yesitisasport

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