Possible to save all columns except hidden?

JadonR

Board Regular
Joined
Apr 15, 2009
Messages
154
Office Version
  1. 365
I would like to save a worksheet as a csv file, but I don't want to save the columns that are hidden. Is this even possible?

I'm currently using the following macro to save the worksheet as the csv. Maybe it could be modified?

Code:
Sub Export()
'
' Macro2 Macro
'

'
Application.ScreenUpdating = False
    Columns("B:Z").Select
    Selection.Copy
    Sheets.Add.Name = "Export"
    Sheets("Export").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Columns("M:M").Select
    Selection.Delete Shift:=xlToLeft
    Columns("V:V").Select
        Selection.NumberFormat = "m/d/yyyy h:mm"
    Columns("W:W").Select
    Selection.Delete Shift:=xlToLeft
    Range("a5").Select
    Application.DisplayAlerts = False
    ChDir "\\SERVER\CPSQL"
    ActiveWorkbook.SaveAs Filename:= _
        "\\SERVER\CPSQL\SGProducts.csv" _
        , FileFormat:=xlCSV, CreateBackup:=False
    Workbooks.Close
Application.DisplayAlerts = True
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Whenever I have a situation like this, where I don't want to export all the columns, I just copy all the columns I do want to export to a new sheet, and export that sheet.
 
Upvote 0
That is definitely the obvious choice :). I am trying to get something a little more automated though. Apparently what I was asking for is not possible. I guess I'll look for an alternative way...thanks.
 
Upvote 0
That is definitely the obvious choice :smile:. I am trying to get something a little more automated though. Apparently what I was asking for is not possible. I guess I'll look for an alternative way...thanks.
Oh, I automate it! I have a macro that does everything, so I export the whole thing with a single click of a button. You should be able to use the Macro Recorder to give you most of the code you would need to do that. Just record yourself performing those steps. It might be easier to copy the whole sheet over, then delete the columns you do not want.
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,240
Members
452,898
Latest member
Capolavoro009

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