VBA: Save data in CSV quickly in folder

azov5

New Member
Joined
Dec 27, 2018
Messages
40
If sheet "filename" found,
Save sheet "filename" with ID in A2 in C:\Users\SR\Downloads\CSV as CSV file.
If the same name appears in folder save file with name(number) but do overwrite it.
Also, define the range in columns and rows (say a1:x5000) so that the saved data can be adjusted.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If sheet "filename" found,
Save sheet "filename" with ID in A2 in C:\Users\SR\Downloads\CSV as CSV file.
If the same name appears in folder save file with name(number) but do overwrite it.
Also, define the range in columns and rows (say a1:x5000) so that the saved data can be adjusted.

When you use VBA, you'll need to very distinct about the difference between the workbook, which has the filename, and the worksheet, which has the sheet name (and index number) for every sheet.

You'll need to use the VBA "DIR" function for basic work in the folder.

Finding the range you have to work with can be slightly tricky, there isn't only one way to do that, there isn't only one way to keep the data in a group, but if you can rely and depend on the data starting at A1 and moving down and to the right that helps. You ask to define the range, but you don't say what you plan to do with it, so, what kind of name are you looking for?

Maybe you want to define your source data as a table, or name it as a range? Learning how to name the range would help, you'll also want to make sure that as you add new rows, the name is still valid.
 
Upvote 0
This is a very simple step but I can not do it with VBA.

In
sheet named "filename" ID is always in A2.

If the same name appears in folder save file with name(number) but do overwrite it.

changed to

If the same name appears in folder save file with filename i.e, ID(number) but do not overwrite it.

By
ID(number) I mean to say we want to save an excel book with name "exceldata" several times so the step will ask do you want to overwrite it. But here I don't want to overwrite it instead we can save the expected csv file as ID(1), ID(2) etc. And ID number we will get from Workbook sheet named "filename" and it is always in A2. Hope this makes sense.


 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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