Test Auto
Test Auto
' Copy data from source sheet to destination sheet based on defined columns
For i = 2 To lastRow ' Start from row 2 to skip headers
outputLastRow = destWs.Cells(destWs.Rows.Count, 1).End(xlUp).Row + 1
destWs.Cells(outputLastRow, 1).Value = srcWs.Cells(i, 1).Value ' Column A -
> A
destWs.Cells(outputLastRow, 2).Value = srcWs.Cells(i, 7).Value ' Column G -
> B
destWs.Cells(outputLastRow, 3).Value = srcWs.Cells(i, 17).Value ' Column Q
-> C
destWs.Cells(outputLastRow, 4).Value = srcWs.Cells(i, 19).Value ' Column S
-> D
destWs.Cells(outputLastRow, 5).Value = srcWs.Cells(i, 20).Value ' Column T
-> E
destWs.Cells(outputLastRow, 6).Value = srcWs.Cells(i, 21).Value ' Column U
-> F
destWs.Cells(outputLastRow, 7).Value = srcWs.Cells(i, 22).Value ' Column V
-> G
destWs.Cells(outputLastRow, 8).Value = srcWs.Cells(i, 25).Value ' Column Y
-> H
Next i
' Sort the data in the destination sheet by column C (3rd column) after header
With destWs.Sort
.SortFields.Clear
.SortFields.Add Key:=destWs.Range("C2:C" & outputLastRow),
Order:=xlAscending
.SetRange destWs.Range("A1:H" & outputLastRow)
.Header = xlYes
.Apply
End With