excel to CSV Cell/column format

pjvallec

New Member
Joined
Mar 18, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need help with this coding. I need Colum Aw to be formatted at Text. i tired this code Range("AW1:AW51").NumberFormat = "@"

10077890493189
1647610297624.png





VBA Code:
Sub ExportCSV()
Application.ScreenUpdating = False

        Dim FlSv As Variant
        Dim MyFile As String
        Dim sh As Worksheet
        Dim MyFileName As String
        Dim DateString As String

        DateString = Format(Now(), "yyyy-mm-dd_hh_mm_ss_AM/PM") '<~~ uses current time from computer clock down to the second
        MyFileName = "Ohio Load #" & " " & DateString

       Sheets("csv").Visible = True
        Set sh = Sheets("csv")
        sh.Copy
        FlSv = Application.GetSaveAsFilename(MyFileName, fileFilter:="CSV (Comma delimited) (*.csv), *.csv", Title:="Where should we save this?")


     If FlSv = False Then GoTo UserCancel Else GoTo UserOK

UserCancel:             '<~~ this code is run if the user cancels out the file save dialog
        ActiveWorkbook.Close (False)
        MsgBox "****Export Canceled***"
        Exit Sub

UserOK:                 '<~~ this code is run if user proceeds with saving the file (clicks the OK button)
        MyFile = FlSv
        With ActiveWorkbook
            [COLOR=rgb(0, 0, 0)]Range("AW1:AW51").NumberFormat = "@"[/COLOR]
            .SaveAs (MyFile), FileFormat:=xlCSV, CreateBackup:=False
            .Close False
            MsgBox "Export Completed!!"
        End With

Sheets("csv").Visible = False
Application.ScreenUpdating = True
    End Sub
 
I'm working off a template, once I export the file and rename the template it gives me the #REF!

1647883503578.png


1647883573529.png
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You haven't really explained the whole flow/process here, but I think your best bet may be to close the file, and re-open your original template.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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