Copy format along with formulas using Resize - VBA

MPaul100

New Member
Joined
Aug 21, 2019
Messages
24
Hi, the code below find the last 3 columns before last 3, copies them, inserts them as formulas and the pasting the copied columns as values. It works properly, but it doesn't copy the format as it should. Basically, it copies over only the format of the last column, not all 3(they are different).
Any idea on an easy fix?
VBA Code:
Sub ColChange()
Dim lastCol As Long

Application.Calculation = xlManual
With Sheets("2020")
lastCol = Cells(8, Columns.Count).End(xlToLeft).Column
Cells(8, lastCol - 3).Resize(, 3).EntireColumn.Insert
Cells(8, lastCol - 6).Resize(, 3).EntireColumn.Copy
Cells(1, lastCol - 3).Resize(, 3).PasteSpecial Paste:=xlPasteFormulas
Cells(1, lastCol - 3).Resize(, 3).PasteSpecial Paste:=xlPasteFormats
Cells(1, lastCol - 6).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End With
Application.Calculation = Automatic
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
How about
VBA Code:
Sub ColChange()
Dim lastCol As Long

Application.Calculation = xlCalculationManual
With Sheets("2020")
   lastCol = Cells(8, Columns.count).End(xlToLeft).Column
   .Cells(8, lastCol - 6).Resize(, 3).EntireColumn.Copy
   .Cells(1, lastCol - 3).Insert
   .Cells(1, lastCol - 6).PasteSpecial Paste:=xlPasteValues
   Application.CutCopyMode = False
End With
Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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