+ Reply to Thread
Results 1 to 4 of 4

Adding Data to more Data

Hybrid View

  1. #1
    Registered User
    Join Date
    10-27-2015
    Location
    CT, USA
    MS-Off Ver
    2010
    Posts
    36

    Adding Data to more Data

    My problem so far is trying to combine data from separate sheets into one.

    In other words, just an update without deleting prior data.

    I have some code here that will shed some light;

      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

  2. #2
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Adding Data to more Data

    If you already do have data that you don't want to overwrite, then it sounds like you simply need to first determine where that data ends. The new data you add will be added after the data you already have.

    This statement might help.

    last_row = Cells(Rows.Count, 1).End(xlUp).Row

    It determines the last row in column 1 that has data in it. Your data would start at last_row + 1, for example.

  3. #3
    Registered User
    Join Date
    10-27-2015
    Location
    CT, USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Adding Data to more Data

    How can I incorporate last_row = Cells(Rows.Count, 1).End(xlUp).Row into the above code?

  4. #4
    Registered User
    Join Date
    10-27-2015
    Location
    CT, USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Adding Data to more Data

    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.

    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 11
    Last Post: 08-13-2015, 08:12 AM
  2. Replies: 2
    Last Post: 10-23-2013, 09:32 AM
  3. [SOLVED] adding target lines into graphs without adding an extra column of data
    By ea223 in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-16-2013, 12:32 PM
  4. Replies: 2
    Last Post: 04-06-2012, 02:42 PM
  5. Replies: 3
    Last Post: 02-07-2011, 10:11 PM
  6. Replies: 0
    Last Post: 12-05-2008, 01:32 PM
  7. Replies: 4
    Last Post: 04-12-2006, 09:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1