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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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