CSVsubsetSplit
Splits the CSV data into a set of files in which each piece has a related portion of the data.
Syntax
expression.CSVsubsetSplit
(filePath, [subsetColumns:= 1], [headers:= True], [repeatHeaders:= True], [streamSize:= 20], [oConfig:=Nothing])
Parameters
Part | Description |
---|---|
filePath | Required. Identifier specifying a String Type variable representing the full path to the target CSV file. |
subsetColumns | Optional. Identifier specifying a Variant Type variable representing the indexes of the fields on which the data groups will be created. |
headers | Optional. Identifier specifying a Boolean Type variable indicating whether the target CSV file has a header record. |
repeatHeaders | Optional. Identifier specifying a Boolean Type variable indicating whether the header record, from the target CSV file, will be copied to all created files. |
streamSize | Optional. Identifier specifying a Long Type variable representing the buffer size factor used to read the target CSV file. |
oConfig | Optional. Identifier specifying a CSVparserConfig Object variable holding all the configurations to parse the CSV file. |
Returns value
Type: Collection
object
Behavior
The CSVsubsetSplit
method will create a file for each different value (data grouping) in the fields at the subsetColumns position, then all related data is appended to the respective file. Use the headers parameter to include a header record in each new CSV file. The subsetColumns parameter can be a single value or an array of Long
values. When the CSV file has a header record and the user sets the header parameter to False
, the header row is saved in a separate file and the rest of CSV files will have no header record. The user can control when to include the headers by using the repeatHeaders parameter.
📝Note
The result subsets will be saved in a folder named [*-WorkDir], where (*) denotes the name of the source CSV file.
☕Example
Sub SplitCSV()
Dim CSVint As CSVinterface
Dim path As String
Set CSVint = New CSVinterface
path = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
CSVint.CSVsubsetSplit path, 3, True ' Split the CSV and rank the resulting files by
' the contents of the third column. Header is
' assumed to be present on the file.
Set CSVint = Nothing
End Sub