Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Convert one .csv file to multiple excel files

Hi,

I have a csv file which has a number of datasets (for several years) ,
each yearly datasets are separated by a blank row. Can anyone please
suggest an easy way to convert this dataset to an excel file for each
individual year?

thanks in advance

Nagendra

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 284
Default Convert one .csv file to multiple excel files

For the example subroutine below, I had the original csv file named
"multiYr.csv" and located it in the folder "C:\Test". The subroutine
creates muliple csv files from the sections separated by a blank line and
saves them with names "myTemp0.csv", "myTemp1.csv", myTemp2.csv, etc and
locates these new csv files in C:\Temp along with the larger original. For
each of these csv files, a new workbook is created. You would locate the
subroutine in a module, run it and then manually move through the windows
and do a 'File SaveAs' for each, giving it an appropriate name and
location.

__________________________________

Sub BreakApartCSV()

Const ForReading = 1
Const ForWriting = 2

Dim strLine As String
Dim strTemp As String
Dim txtArray()

Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFile = FSO.OpenTextFile("C:\Test\multiYr.csv", ForReading)

strTemp = ""
i = 1


Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If strLine = "" Then
ReDim Preserve txtArray(i)
txtArray(i - 1) = strTemp
i = i + 1
strTemp = ""
Else
strTemp = strTemp & strLine
End If
Loop

txtArray(i - 1) = strTemp

For X = 0 To UBound(txtArray)
strPathTmp = "C:\Test\myTemp" & CStr(X) & ".csv"
Set tmpTextFile = FSO.CreateTextFile(strPathTmp, ForWriting)
tmpTextFile.Write txtArray(X)
tmpTextFile.Close
Workbooks.OpenText Filename:=strPathTmp, DataType:=xlDelimited
Next X

objFile.Close
Set FSO = Nothing

End Sub


___________________________________

Steve




"singh" wrote in message
ups.com...
Hi,

I have a csv file which has a number of datasets (for several years) ,
each yearly datasets are separated by a blank row. Can anyone please
suggest an easy way to convert this dataset to an excel file for each
individual year?

thanks in advance

Nagendra



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert pdf files into an Excel file JED Excel Discussion (Misc queries) 0 August 29th 07 12:54 AM
Convert Multiple CSV Files to XLS Files (Again) Dave Excel Discussion (Misc queries) 1 July 11th 07 04:43 PM
how do I join multiple excel files into 1 file? John Excel Discussion (Misc queries) 4 February 22nd 06 07:38 PM
Can I embed or link multiple .pdf files into or to an excel file? GrubbyG Excel Discussion (Misc queries) 1 October 3rd 05 08:40 PM
Convert multiple XLS files to TXT finao Excel Discussion (Misc queries) 2 June 8th 05 03:14 PM


All times are GMT +1. The time now is 09:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"