How to add more data into sheet?

LogicUser

New Member
Joined
Nov 17, 2015
Messages
3
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?

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
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I ended up being able to transfer data without having to delete prior. Now Im having trouble selecting the column headers along with the data when added to previous data. I dont want the column header, just the data.
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


Data = getDataFromFile(parFileName, parDelimiter)


If Not isArrayEmpty(Data) Then
  
With Sheets(parSheetName)


lr = Cells(Rows.Count, 1).End(xlUp).Row
    
.Cells(lr, 1).Resize(UBound(Data, 1), UBound(Data, 2)) = Data
  End With
End If
End Sub
 
Upvote 0
Yeah, I had posted and then tried to edit the post to delete it, and did not see a way to delete the post altogether so I wrote "Cancel". Pretend the post does not exist...
 
Upvote 0

Forum statistics

Threads
1,215,389
Messages
6,124,665
Members
449,178
Latest member
Emilou

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