Luis Diaz
asked on
Excel VBA: export range as csv
Hello experts,
The following procedure allows me to export range to a csv file:
I would like to add the following requirements:
1-Inputbox related to the range to export: "Please Enter range that you want to export, example: A;C"
2-Loop from first row till the last used range involved by range reported in first inputbox.
If you have questions, please contact me.
The following procedure allows me to export range to a csv file:
Sub CSV_Export_Based_On_Range()
Dim myCSVFileName As String
Dim myWB As Workbook
Dim tempWB As Workbook
Dim rngToSave As Range
Application.DisplayAlerts = False
Set myWB = ThisWorkbook
Set rngToSave = Range("A2:C30")
rngToSave.Copy
Set tempWB = Application.Workbooks.Add(1)
On Error GoTo Error_Routine
With tempWB
.Sheets(1).Range("A1").PasteSpecial xlPasteValues
.SaveAs Filename:=ActiveSheet.Name & "_" & Format(Now, "YYYYMMDDMMSS"), _
FileFormat:=xlCSV, _
CreateBackup:=False, Local:=True
.Close
End With
Shell "C:\WINDOWS\explorer.exe """ & ActiveWorkbook.Path & "\", vbNormalFocus
Application.ScreenUpdating = True
Exit Sub
Error_Routine:
MsgBox err.Description, vbExclamation, "Something went wrong!"
Application.ScreenUpdating = True
End Sub
I would like to add the following requirements:
1-Inputbox related to the range to export: "Please Enter range that you want to export, example: A;C"
2-Loop from first row till the last used range involved by range reported in first inputbox.
If you have questions, please contact me.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much Subodh.
I tested and it works!
I have reviewed the question and I don't know why I request to export based on the following format:
A;C. I think that the most logic is to request to report like this A:C. I don't know if this can be modified.
If not I will select your previous proposal as solution.
I tested and it works!
I have reviewed the question and I don't know why I request to export based on the following format:
A;C. I think that the most logic is to request to report like this A:C. I don't know if this can be modified.
If not I will select your previous proposal as solution.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Subodh.
I tested and it works!
Thank you for your help.
I tested and it works!
Thank you for your help.
You're welcome Luis!
ASKER