Extracting specific columns from worksheet and importing into new worksheet

sdhutty

Board Regular
Joined
Jul 15, 2016
Messages
207
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:

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 :)
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,375
Messages
6,124,576
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top