Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro that copies a table from worksheet under a table in another 1

Status
Not open for further replies.

RyanScharfy

Technical User
Jun 17, 2003
86
0
0
US
Example (Using Excel 2003)

Sheet1 - Table1, variable rows

Sheet2 - Table2, same format, variable rows.

I want to copy Table2 directly underneat Table 1 so it is one big table (basically merge the tables)

Here's my code - less the missing piece

Sub CopyTable()
'
' CopyTable Macro
'
' Go to row 2 and highlight all data below and copy
Sheets("Sheet2").Select
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

' Go to Sheet 1, and scroll down column A to get to the
' end of the table
Sheets("Sheet1").Select
Range("A1").Select
Selection.End(xlDown).Select

' How to do go one more cell down?

' Paste
ActiveSheet.Paste
End Sub
 



Hi,

I AVOID using the Select and Activate methods...
Code:
Sub CopyTable()
'
' CopyTable Macro
'
    Dim lRow As Long
' Go to row 2 and highlight all data below and copy
    Range(Sheets("Sheet2").Rows("2:2"), Sheets("Sheet2").Rows("2:2").End(xlDown)).Copy

' Go to Sheet 1, and scroll down column A to get to the
' end of the table
    With Sheets("Sheet1")
        lRow = .Range("A1").End(xlDown).Row + 1
        .Cells(lRow, "A").PasteSpecial xlPasteAll
    End With
End Sub

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip,

Worked like a charm. If I might be so bold as to ask... you have short version of why you dislike the Select and Activate method? Does it tend to get a little buggy compared to your method depending on the lists in question?
 



Good coders use the Select and Activate methods sparingly.

faq707-4105

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top