Results 1 to 2 of 2

Consolidating Data into one workbook

Threaded View

  1. #1
    Registered User
    Join Date
    06-13-2011
    Location
    Boulder, Colorado
    MS-Off Ver
    Excel 2010
    Posts
    61

    Consolidating Data into one workbook

    I have a lot of data collected during various experiments that are saved as .CSV files which I am trying to consilate into one workbook with a macro. I found some sites that were able to guide me in the right direction and my code is working except all of my data that I need pasted into my "master" worksheet are not being pasted in their designated cells. Every value is being pasted into column A regardless of where I have inteneded it to be pasted. I have included my code below along with my master spreadsheet showing how the code its variables. I don't believe this is a very hard fix but I can;t seem to figure out a good solution. Any help is greatly appreciated.

    Public currentWB As Workbook
    Public dataWB As Workbook
    Public strCopyRange As String
    
        Dim strWhereToCopy As String, strStartCellColName As String
        Dim strListSheet As String
        
        strInfoSheet = "Info"
        
        On Error GoTo ErrH
        Sheets(strInfoSheet).Select
        Range("B2").Select
        
        'this is the main loop, we will open the files one by one and copy their data into the masterdata sheet
        Set currentWB = ActiveWorkbook
        Do While ActiveCell.Value <> ""
            
            strFileName = ActiveCell.Offset(0, 1) & ActiveCell.Value
            strCopyRange = ActiveCell.Offset(0, 2) & ":" & ActiveCell.Offset(0, 3)
            strWhereToCopy = ActiveCell.Offset(0, 4).Value
            strStartCellColName = Mid(ActiveCell.Offset(0, 5), 2, 1)
            
            Application.Workbooks.Open strFileName, UpdateLinks:=False, ReadOnly:=True
            Set dataWB = ActiveWorkbook
        
            Sheets(strCopyRange).Select
            Selection.Copy
            
            currentWB.Activate
            
            Range(strWhereToCopy).Select
            lastRow = LastRowInOneColumn(strStartCellColName)
            Cells(lastRow + 1, 1).Select
    
            Selection.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
            Application.CutCopyMode = False
            dataWB.Close False
            Sheets(strInfoSheet).Select
            ActiveCell.Offset(1, 0).Select
        Loop
        Exit Sub
    
    ErrH:
        MsgBox "It seems some file was missing. The data copy operation is not complete."
        Exit Sub
    End Sub
    
    Public Function LastRowInOneColumn(col)
        Dim lastRow As Long
        With ActiveSheet
        lastRow = .Cells(.Rows.Count, col).End(xlUp).Row
        End With
        LastRowInOneColumn = lastRow
    End Function
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

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