Hello. I found this code online ,which pulls data from a csv file.
Im trying to make this section of the code put data into a main worksheet with existing data without deleting said existing data.
How can I do this please?
Im trying to make this section of the code put data into a main worksheet with existing data without deleting said existing data.
How can I do this please?
Code:
Sub RefreshData()
Dim sPath As String
sPath = ThisWorkbook.Path & "\Data_File.csv"
copyDataFromCsvFileToSheet sPath, ",", "Sheet1"
End Sub
Private Sub copyDataFromCsvFileToSheet(parFileName As String, _
parDelimiter As String, parSheetName As String)
Dim Data As Variant 'Array for the file values
'Function call - the file is read into the array
Data = getDataFromFile(parFileName, parDelimiter)
'If the array isn't empty it is inserted into
'the sheet in one swift operation.
If Not isArrayEmpty(Data) Then
'If you want to operate directly on the array,
'you can leave out the following lines.
With Sheets(parSheetName)
'Delete any old content
.Cells.ClearContents
'A range gets the same dimensions as the array
'and the array values are inserted in one operation.
.Cells(1, 1).Resize(UBound(Data, 1), UBound(Data, 2)) = Data
End With
End If
End Sub