Hello,
I currently have a piece of coding whereby it extracts the worksheet called 'Register' & puts it into a new workbook ready for the option to save it.
However when it extracts, I want it only to extract certain columns.
These columns are columns:
B, C, D, E, F, G, H, I, J, K
Also, I currently have filters on the workbook, so when it extracts I want (if filters are on), the filtered data to only extract to the new workbook.
The current process is that if I run the coding - the filters turn off - extract the whole worksheet to a new workbook - and the filters turn back on.
Here is the current coding:
Thank you
I currently have a piece of coding whereby it extracts the worksheet called 'Register' & puts it into a new workbook ready for the option to save it.
However when it extracts, I want it only to extract certain columns.
These columns are columns:
B, C, D, E, F, G, H, I, J, K
Also, I currently have filters on the workbook, so when it extracts I want (if filters are on), the filtered data to only extract to the new workbook.
The current process is that if I run the coding - the filters turn off - extract the whole worksheet to a new workbook - and the filters turn back on.
Here is the current coding:
Code:
Sub Extraction_Click()
If MsgBox("This will begin the process to extract the 'Register' worksheet. Proceed?", vbYesNo) = vbNo Then Exit Sub
Application.DisplayAlerts = False
Dim wb As Workbook, InitFileName As String, fileSaveName As String
InitFileName = ThisWorkbook.Path & "\ Extracted_Register_" & Format(Date, "dd-mm-yyyy")
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Sheets("Register").Copy
' or below for more than one sheet
' Sheets(Array("Output", "Sheet2", "Sheet3")).Copy
Set wb = ActiveWorkbook
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitFileName, _
filefilter:="Excel files , *.xlsx")
With wb
If fileSaveName <> "False" Then
.SaveAs fileSaveName
.Close
Else
.Close False
Exit Sub
End If
End With
MsgBox ("Extraction Completed")
If ActiveSheet.AutoFilterMode = False Then
Range("A5:R5").AutoFilter
End If
Application.DisplayAlerts = True
End Sub
Thank you