VBA Help Please

How_Do_I

Well-known Member
Joined
Oct 23, 2009
Messages
1,838
Office Version
  1. 2010
Platform
  1. Windows
Hello, I'm trying to copy the last column on Sheet 1 and paste the data on to Sheet 2. I've started with this code but I can't get what I need. Can anyone help please?

Sub LastColumn()
Worksheets("Sheet1").Activate
Range("B2").End(xlToRight).Select
ActiveCell.End(xlDown).Copy
Worksheets("Sheet2").Activate
Range("H2").PasteSpecial
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I am assuming you want to copy the entire column to the first blank column in Sheet2

Code:
Sub copylc()
Dim lc As Long
Dim lc2 As Long
lc = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
lc2 = Sheets("Sheet2").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets("Sheet1").Columns(lc).Copy Destination:=Sheets("Sheet2").Cells(1, lc2 + 1)

End Sub
 
Upvote 0
How about
Code:
Sub LastColumn()
   With Worksheets("Sheet1")
      .Cells(2, Columns.Count).End(xlToLeft).EntireColumn.Copy
         Worksheets("Sheet2").Range ("H1")
   End With
End Sub
 
Upvote 0
Hello Fluff,

I couldn't get your code to run, it doesn't like this line:

Worksheets("Sheet2").Range ("H1")
 
Upvote 0
The underscore got stripped out
Code:
Sub LastColumn()
   With Worksheets("Sheet1")
      .Cells(2, Columns.Count).End(xlToLeft).EntireColumn.Copy[COLOR=#ff0000] _[/COLOR]
         Worksheets("Sheet2").Range("H1")
   End With
End Sub
 
Upvote 0
Oh, the last column on Sheet 1 is data placed there by a formula so it is causing as issue please Fluff?
 
Upvote 0
OK, how about
Code:
Sub LastColumn()
   With Worksheets("Sheet1")
       Worksheets("Sheet2").Range("H1").EntireColumn.Value = .Cells(2, Columns.Count).End(xlToLeft).EntireColumn.Value
   End With
End Sub
 
Upvote 0
Thanks for your help Fluff, that last one is working...
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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