VBA/Excel - Macro to insert columns after last column entry keeping same format/formulas as adjacent columns

mr600

New Member
Joined
Jan 6, 2021
Messages
1
Office Version
  1. 365
Hi there,

I was hoping someone could help me with the following:

I need a macro that will go into given columns (multiple) and insert a column towards the right-hand-side (i.e. next to the last column with data in it), whilst keeping the same format/formulas as the columns to the left. The columns will have given dates and some formulas below - I need to keep these formulas such that the dates/data update automatically.

I need this to be repeated for a variety of tabs with different names.

Are you able to provide a VBA code to help with this please?

Thanks
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
I am not really sure what you are looking for, but we can start with this and work from there.

VBA Code:
Sub t()
Dim lc As Long
With ActiveSheet
    lc = .Cells.Find("*", , xlFormulas, xlPart, xlByColumns, xlPrevious).Column
    .Cells(1, lc).EntireColumn.Copy
    .Cells(1, lc + 1).PasteSpecial xlPasteFormulasAndNumberFormats
    .Cells(1, lc + 1).PasteSpecial xlPasteFormats
End With
End Sub
This copies the formulas , number formats and other formatting from the last column with data to the next available column. If the formulas have absolute references (row and column preceded with $ symbol) then those will continue to evaluate the same cells, but if they are relative references then the cells evaluated will change accordingly by one column.
 

Watch MrExcel Video

Forum statistics

Threads
1,132,799
Messages
5,655,367
Members
418,193
Latest member
RichKatzRich

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
Top