Updated code:
Sub tgr()
Dim ws(1 To 2) As Worksheet
Dim strOutput As String
Dim rIndex As Long
Dim i As Long
Set ws(1) = Sheets("Sheet3")
Set ws(2) = Sheets("Sheet4")
strOutput = Join(Application.Transpose(ws(1).Range("U1", ws(1).Cells(Rows.Count, "U").End(xlUp)).Value), Chr(10))
strOutput = strOutput & Chr(10) & Join(Application.Transpose(ws(2).Range("U1", ws(2).Cells(Rows.Count, "U").End(xlUp)).Value), Chr(10))
For i = 1 To UBound(ws)
With ws(i).Range("AD1", Intersect(ws(i).Columns("AG"), ws(i).Range("AD:AG").Find("*", ws(i).Range("AD1"), , , , xlPrevious).EntireRow))
For rIndex = 1 To .Rows.Count
strOutput = strOutput & Chr(10) & Join(Application.Transpose(Application.Transpose(Intersect(ws(i).Rows(rIndex), .Cells).Value)), Chr(10))
Next rIndex
End With
Next i
Close #1
Open Environ("UserProfile") & "\Desktop\Output.txt" For Output As #1
Print #1, strOutput
Close #1
Erase ws
End Sub
Bookmarks