2

I'm working on a code that will copy several columns of data that are not in order. I couldn't figure out how to do it in one step so i was trying to get it in two. After the first set of columns posts I'm having trouble getting it to go back to the sheet I was on to copy the next set of columns. This is what my code looks like so far.

Survey_Macro1 Macro

range("A:D").Select
range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets.Add.Name = "Data"
ActiveSheet.Paste
ThisWorkbook.Save
ThisWorkbook.Sheets("Table").Activate
Application.CutCopyMode = False
range("AK:AL").Select
range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ThisWorkbook.Worksheets("Data").range(E1).Select
ActiveSheet.Paste
Cocoberry2526
  • 187
  • 3
  • 15

1 Answers1

4

See How to avoid using Select in Excel VBA macros.

Sub yg23iwyg()
    Dim wst As Worksheet

    Set wst = Worksheets.Add
    wst.Name = "Data"
    With Worksheets("Table")
        .Range(.Cells(1, "A"), .Cells(.Rows.Count, "D").End(xlUp)).Copy _
            Destination:=wst.Cells(1, "A")
        .Range(.Cells(1, "AK"), .Cells(.Rows.Count, "AL").End(xlUp)).Copy _
            Destination:=wst.Cells(1, "E")

        'alternate with Union'ed range - becomes a Copy, Paste Special, Values and Formats because of the union
        .Range("A:D, AK:AL").Copy _
            Destination:=wst.Cells(1, "A")
    End With

End Sub
Community
  • 1
  • 1