Macro to Query Select Fields

Grepees

Board Regular
Joined
Apr 15, 2009
Messages
81
• I have an Excel Sheet with Fields from A to Z
• I need to create a report which will be a selection of some of the Fields. This may change from moonth to month depending on what i'd like to show
• I am looking for a Macro that can to the following;
♦ Select a list of fields in a sheet eg. A, D, F, L, S T, O
♣ Export those fields into a new sheet
◘ Save the new sheet at a designated location ( i will provide the path and File name) eg. June Month end Report

Any help on this would be very much approciated. Thank you very much in advance you good people out there.
 
If you have header in row1.
AdvancedFilter
Code:
Sub test()
    Dim ws As Worksheet, Cols, i&, wb As Workbook
    Cols = InputBox("Enter columns")
    If Cols = "" Then Exit Sub
    Set ws = ActiveSheet
    Set wb = Workbooks.Add(1)
    Cols = Split(Cols, ",")
    For i = 0 To UBound(Cols)
        ws.Range(Cols(i) & 1).Copy wb.Sheets(1).Cells(1, i + 1)
    Next
    ws.Range("a1").CurrentRegion.AdvancedFilter 2, , wb.Sheets(1).Range("a1").CurrentRegion
    wb.SaveAs ThisWorkbook.Path & "\abc", 51
    wb.Close
End Sub
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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