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
Bookmarks