I am using the following Macro to copy certain columns to a new Worksheet in a particular order which is working fine however I have two issues:
1 - When the new worksheet is created the column widths are not being exported over so I have go to the new worksheet an manually adjust the width again.
2 - I have a number of columns which will be move when additional columns are added i.e. from column AB to AC which means I have to change the code again.Is there a way to track these so I do not have to change the code again. In row 5 each of the columns has a unique heading.
Sub CreateExportSheet()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
If SheetExists("Export Sheet") = True Then
MsgBox "The sheet Export Sheet already exist"
Exit Sub
End If
Application.ScreenUpdating = False
Set DestSh = Worksheets.Add
DestSh.Name = "Export Sheet"
Sheets("Sheet1").Columns("D:D").Copy Destination:=Sheets("Export Sheet").Columns("A:A")
Sheets("Sheet1").Columns("Q:Q").Copy Destination:=Sheets("Export Sheet").Columns("B:B")
Sheets("Sheet1").Columns("S:S").Copy Destination:=Sheets("Export Sheet").Columns("C:C")
Sheets("Sheet1").Columns("U:U").Copy Destination:=Sheets("Export Sheet").Columns("D:D")
Sheets("Sheet1").Columns("AB:AB").Copy Destination:=Sheets("Export Sheet").Columns("P:P")
Sheets("Sheet1").Columns("AH:AH").Copy Destination:=Sheets("Export Sheet").Columns("E:E")
Sheets("Sheet1").Columns("N:N").Copy Destination:=Sheets("Export Sheet").Columns("F:F")
Sheets("Sheet1").Columns("AI:AI").Copy Destination:=Sheets("Export Sheet").Columns("G:G")
Application.ScreenUpdating = True
End Sub
Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(Sheets(SName).Name))
End Function
Can anyone help?
Bookmarks