Help with Last Cell VBA

chaddres

Board Regular
Joined
Jun 14, 2014
Messages
143
Office Version
  1. 365
Platform
  1. Windows
What am I doing wrong with the code in red? I want to select Cell A2 on Sheet 2 and then select the data in A2:A LRowS1 (the last row in that column). Thank you so much for any guidance.

Sheets("Macro Workbook").Select
Range("A1").Select
'Sheets.Add After:=ActiveSheet
'Sheets("Sheet5").Select
'Sheets("Sheet5").Name = "Time Export"
Sheets("Sheet 1").Select
Range("A:A,C:C,D:D,G:G,H:H,P:P,V:V").Select
Selection.Copy
Sheets("Time Export").Select
ActiveSheet.Paste
Range("A1").Select
LRowTE = Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("Sheet 2").Select
Range("A2").Select
LRowS1 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:A&LRowS1,C2:CLRowS1,D2:DLrowS1,G2:GLrowS1,H2:HLrowS1,P2:PLrowS1,V2:VLrowS1").Select

Selection.Copy
Sheets("Time Export").Select
Range("ALrowTE").Select
ActiveSheet.Paste
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Do you just want to copy col A, or do you want to copy the other columns as well?
 
Upvote 0
Ok, how about
VBA Code:
Sub chaddres()
   With Sheets("Sheet 2")
      Intersect(.Range("A2", .Range("A" & Rows.Count).End(xlUp)).EntireRow, .Range("A:A,C:D,G:H,P:P,V:V")).Copy Sheets("Time Export").Range("ALrowTE")
   End With
End Sub
 
Upvote 0
Fluff, now I have this:

Sheets("Macro Workbook").Select
Range("A1").Select
'Sheets.Add After:=ActiveSheet
'Sheets("Sheet5").Select
'Sheets("Sheet5").Name = "Time Export"
Sheets("Sheet 1").Select
Range("A:A,C:C,D:D,G:G,H:H,P:P,V:V").Select
Selection.Copy
Sheets("Time Export").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
LRowTE = Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("Sheet 2").Select
Range("A2").Select
With Sheets("Sheet 2")
Intersect(.Range("A2", .Range("A" & Rows.Count).End(xlUp)).EntireRow, .Range("A:A,C:D,G:H,P:P,V:V")).Copy Sheets("Time Export").Range("ALrowTE")
End With
ActiveSheet.Paste

Where am I wrong? I get an error on the Intersect line. I appreciate your help!!!
 
Upvote 0
The error says "Can't execute code in break mode". I attached a picture.

VBA Code:
Sheets("Macro Workbook").Select
Range("A1").Select
'Sheets.Add After:=ActiveSheet
'Sheets("Sheet5").Select
'Sheets("Sheet5").Name = "Time Export"
Sheets("Sheet 1").Select
Range("A:A,C:C,D:D,G:G,H:H,P:P,V:V").Select
Selection.Copy
Sheets("Time Export").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
LRowTE = Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("Sheet 2").Select
Range("A2").Select
With Sheets("Sheet 2")
Intersect(.Range("A2", .Range("A" & Rows.Count).End(xlUp)).EntireRow, .Range("A:A,C:D,G:H,P:P,V:V")).Copy Sheets("Time Export").Range("ALrowTE")
End With
ActiveSheet.Paste
 

Attachments

  • Capture.PNG
    Capture.PNG
    40.3 KB · Views: 4
Upvote 0
Sorry. The error is "Run-time error 1001: application-defined or object-defined error"
 

Attachments

  • Capture.PNG
    Capture.PNG
    40.9 KB · Views: 5
Upvote 0
Do you have a named range called ALrowTE on the Time Export sheet?
 
Upvote 0
Fluff, THANK YOU SO MUCH!!!!! I figured it out. The last range in the Intersect was wrong (my fault). I was also missing a Select.Copy and where to paste the data. You're a lifesaver!

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'

'
    Sheets("Macro Workbook").Select
    Range("A1").Select
    'Sheets.Add After:=ActiveSheet
    'Sheets("Sheet5").Select
    'Sheets("Sheet5").Name = "Time Export"
    Sheets("Sheet 1").Select
    Range("A:A,C:C,D:D,G:G,H:H,P:P,V:V").Select
    Selection.Copy
    Sheets("Time Export").Select
    Range("A1").Select
    ActiveSheet.Paste
    Range("A1").Select
    LrowTE = Cells(Rows.Count, 1).End(xlUp).Row + 1
    Sheets("Sheet 2").Select
    Range("A2").Select
    With Sheets("Sheet 2")
      Intersect(.Range("A2", .Range("A" & Rows.Count).End(xlUp)).EntireRow, .Range("A:A,C:D,G:H,P:P,V:V")).Copy Sheets("Time Export").Range("A" & LrowTE)
    End With
    Selection.Copy
    Sheets("Time Export").Select
    Range("A" & LrowTE).Select
    ActiveSheet.Paste
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,234
Members
448,951
Latest member
jennlynn

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