Right now the code is so bloated from the half dozen different attempts...
and I believe that the problem is the file, not the code, but...
Sub import()
Dim xlsApp As Excel.Application
Set xlsApp = GetObject(, "Excel.Application")
Dim xlsWb As Excel.Workbook
Set xlsWb = xlsApp.ActiveWorkbook
Dim xlsWs As Excel.Worksheet
Set xlsWs = xlsWb.ActiveSheet
Dim xlsCols As Long
Dim xlsRows As Long
xlsCols = LastColumn(xlsWs)
xlsRows = LastRow(xlsWs)
Debug.Print "Last Func -> Cols: " & xlsCols & "; Rows: " & xlsRows
xlsCols = xlsWs.UsedRange.Columns.Count
xlsRows = xlsWs.UsedRange.Rows.Count
Debug.Print "Range -> Cols: " & xlsCols & "; Rows: " & xlsRows
Dim NextxlsRow As Long
NextxlsRow = xlsRows + 1
Dim xlsGUIDRow As Long
Dim xlsGUIDCol As Long
Dim xlsGUID As Range
Set xlsGUID = FindGUID(xlsWs)
xlsGUIDCol = xlsGUID.Column
xlsGUIDRow = xlsGUID.Row
Dim NewApp As Excel.Application
Set NewApp = CreateObject("Excel.Application")
Dim SourceFileName As String
Dim Filedia As FileDialog
Set Filedia = Application.FileDialog(msoFileDialogOpen)
Filedia.Show
SourceFileName = Filedia.SelectedItems.Item(1)
Dim SourceWb As Workbook
Set SourceWb = NewApp.Workbooks.Open(SourceFileName, , True)
Dim SourceWs As Worksheet
Set SourceWs = SourceWb.ActiveSheet
Dim SrcCols As Long
Dim SrcRows As Long
SrcCols = LastColumn(SourceWs)
SrcRows = LastRow(SourceWs)
Debug.Print "Last Func -> Cols: " & SrcCols & "; Rows: " & SrcRows
SrcCols = SourceWs.UsedRange.Columns.Count
SrcRows = SourceWs.UsedRange.Rows.Count
Debug.Print "Range -> Cols: " & SrcCols & "; Rows: " & SrcRows
Dim SourceGUIDRow As Long
Dim SourceGUIDCol As Long
Dim SourceGUID As Range
Set SourceGUID = FindGUID(SourceWs)
SourceGUIDCol = SourceGUID.Column
SourceGUIDRow = SourceGUID.Row
Dim ThisRowNumb As Long
ThisRowNumb = SourceGUIDRow
Dim SourceColCnt As Long
Dim xlsColCnt As Long
SourceColCnt = SourceGUIDCol + SrcCols
xlsColCnt = xlsGUIDCol + SrcCols
If xlsColCnt > xlsCols Then
xlsWs.Range(xlsWs.Cells(NextxlsRow, xlsColCnt),
xlsWs.Cells(NextxlsRow, xlsColCnt)).Value = "NewCol"
xlsCols = xlsWs.UsedRange.Columns.Count
End If
Dim CopyRange As Range
Dim PasteRange As Range
Debug.Print "Searching... "
While ThisRowNumb <= SrcRows
If ThisRowNumb Like "*00" Then
Debug.Print ThisRowNumb & " Processed"
End If
If xlsWs.Cells.Find(SourceWs.Cells(ThisRowNumb, SourceGUIDCol).Text,
MatchCase:=vbFalse) Is Nothing Then
Debug.Print "Copying... " & SourceWs.Cells(ThisRowNumb,
SourceGUIDCol).Text
Set CopyRange = SourceWs.Range(SourceWs.Cells(ThisRowNumb,
SourceGUIDCol), SourceWs.Cells(ThisRowNumb, SourceColCnt))
CopyRange.Copy
Set PasteRange = xlsWs.Range(xlsWs.Cells(NextxlsRow,
xlsGUIDCol), xlsWs.Cells(NextxlsRow, xlsColCnt))
Debug.Print "Columns: " & CopyRange.Columns.Count & " -> " &
PasteRange.Columns.Count
PasteRange.Select
PasteRange.PasteSpecial Paste:=xlPasteValues
Debug.Print "Columns: " & PasteRange.Columns.Count
NextxlsRow = NextxlsRow + 1
End If
ThisRowNumb = ThisRowNumb + 1
Wend
SourceWb.Close (False)
NewApp.Quit
Debug.Print "Done."
End Sub
Private Function FindGUID(ByRef ws As Worksheet) As Range
Dim WsCols As Long
Dim WsRows As Long
' WsCols = ws.UsedRange.Columns.Count
' WsRows = ws.UsedRange.Rows.Count
WsCols = LastColumn(ws)
WsRows = LastRow(ws)
Dim ColNumb As Long
Dim RowNumb As Long
RowNumb = 1
While RowNumb <= WsRows
ColNumb = 1
While ColNumb <= WsCols
' If UCase(ws.Cells(ColNumb, RowNumb).Text) Like "*GUID*" Then
If UCase(ws.Cells(ColNumb, RowNumb).Text) = "GUID" Then
Set FindGUID = ws.Cells(ColNumb, RowNumb)
Exit Function
End If
ColNumb = ColNumb + 1
Wend
RowNumb = RowNumb + 1
Wend
Set FindGUID = ws.Cells(1, 1)
End Function
Private Function LastColumn(ByRef ws As Worksheet) As Long
LastColumn = ws.Cells.Find(What:="*", _
After:=ws.Cells(1, 1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
End Function
Private Function LastRow(ByRef ws As Worksheet) As Long
LastRow = ws.Cells.Find(What:="*", _
After:=ws.Cells(1, 1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
End Function
Private Function LastCell(ByRef ws As Worksheet) As Range
Dim lngLastRow As Long
Dim lngLastColumn As Long
lngLastRow = LastRow(ws)
lngLastColumn = LastColumn(ws)
If lngLastRow = 0 Then
lngLastRow = 1
End If
If lngLastColumn = 0 Then
lngLastRow = 1
End If
Set LastCell = ws.Cells(lngLastRow, lngLastColumn)
End Function