Paste a formula X number of columns to the right.

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have a value that tells me how many columns to the right of cell J3 I need to paste a formula.

How do I code this to do that? I also need to delete all the columns after that number of columns

So if in Sheets("Material Distribution Spread").Range("I2").Value I have the value of "6"

I need code that would paste in the below formula starting in K3 over 4 columns to O3 (Yes, 1 less then the value in I2)

Then I need to delete any columns that may exist to the right of column 0 (in this instance).

Your help is very mush appreciated.

Code:
Sub SetFirstMonth()

'************
'Set First Month on Material Distribution tab
'*********************************************


Sheets("Material Distribution").Range("J2").Value = Sheets("Material Distribution Spread").Range("G2").Value
'Note J2 is a date

Dim NumMonths As Long

NumMonths = Sheets("Material Distribution Spread").Range("I2").Value

'???? Cells(2, 10).FormulaR1C1 = "=EDATE(R2C10,(COLUMN()-COLUMN(R2C10)))"


End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
correction

'???? Cells(2, 10).FormulaR1C1 = "=EDATE(R3C10,(COLUMN()-COLUMN(R3C10)))"
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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