Find the last column that contains data, and copy and paste it

carefreeant88

New Member
Joined
Nov 27, 2024
Messages
20
Office Version
  1. 2010
Platform
  1. Windows
Good morning,

Struggling a bit with one of my Macros, and hoping you guys can help again?

I basically need to achieve the following:

  1. Search for the sheet called 'Sales Plan Review'
  2. Insert a blank column between columns A and B
  3. On that same sheet, ('Sales Plan Review') go to the last column that contains any data
  4. Once that column is found, copy the whole column
  5. Paste the data from that column, into the blank column that you inserted between A and B
Any help would be greatly appreciated!

Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
In determining where the last column of data is, does every column with data have a title/header in row 1?
Also, do you want to actually move the whole column, or just copy it (Cut vs. Copy)?
 
Last edited:
Upvote 0
Try.
VBA Code:
Sub CopyLastColumn()
Dim Clm&
Sheets("Sales Plan Review").Activate
Range("B1").EntireColumn.Insert
Clm = ActiveSheet.UsedRange.Columns.Count + ActiveSheet.UsedRange.Column - 1
Cells(1, Clm).EntireColumn.Copy Range("B1")
End Sub
 
Upvote 0
If my assumption about headers in row 1 in accurate, and you just want to copy the last column (and not remove the data you are copying from the last column), this code should do what you want:
VBA Code:
Sub MyMoveDataMacro()

'   Go to Sales Plan Review sheet
    Sheets("Sales Plan Review").Select
    
'   Copy last column in between columns A and B
    Cells(1, Columns.Count).End(xlToLeft).EntireColumn.Copy
    Columns("B:B").Insert Shift:=xlToRight
    Application.CutCopyMode = False

End Sub

If you actually want to move the data instead of copying it (so it no longer appears in the last column),
change the ".Copy" to ".Cut"
 
Upvote 0
Solution
If my assumption about headers in row 1 in accurate, and you just want to copy the last column (and not remove the data you are copying from the last column), this code should do what you want:
VBA Code:
Sub MyMoveDataMacro()

'   Go to Sales Plan Review sheet
    Sheets("Sales Plan Review").Select
   
'   Copy last column in between columns A and B
    Cells(1, Columns.Count).End(xlToLeft).EntireColumn.Copy
    Columns("B:B").Insert Shift:=xlToRight
    Application.CutCopyMode = False

End Sub

If you actually want to move the data instead of copying it (so it no longer appears in the last column),
change the ".Copy" to ".Cut"
Superb, thank you so much
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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