I think this is what you mean:
Start in row 2
Do Until cells in columns A-U are blank
Perform an action
Go to next row
Loop
This code should do that but I haven't tested it. It's not practical to build a test file from scratch, plus this is only part of your code and I don't know what else you have. If you attach your file I would be happy to test it.
Dim Rg As Range
Dim R As Long ' Row
Do While Len(FileName) > 0
Set wbk = Workbooks.Open(Path & FileName, UpdateLinks:=0)
'Extract workbook name to Column "X", (adjacent to its value from "R19" or "P19", in Column "W" (see below))
wbdest.Worksheets("Sheet1").Range("X" & Rows.count).End(xlUp).Offset(1) = wbk.Name
wbdest.Worksheets("Sheet1").Range("Y" & Rows.count).End(xlUp).Offset(1).Formula = "=MID(RC[-1],FIND(""ABC"",RC[-1])+3,6)"
R = 2
Set Rg = Range(Cells(R, "A"), Cells(R, "U"))
Do Until Join(Application.Index(Rg.Value, 1, 0)) = ""
If wbdest.Worksheets("Sheet1").Range("Y" & Rows.count).End(xlUp) < 160813 Then
wbk.Sheets(1).Range("B39:S39") = wbdest.Worksheets("Sheet1").Rg.Value
wbdest.Worksheets("Sheet1").Range("W" & Rows.count).End(xlUp).Offset(1) = wbk.Sheets(1).Range("R19")
Else
wbk.Sheets(1).Range("B39:S39") = wbdest.Worksheets("Sheet1").Rg.Value
wbdest.Worksheets("Sheet1").Range("W" & Rows.count).End(xlUp).Offset(1) = wbk.Sheets(1).Range("P19")
End If
R = R + 1
Set Rg = Range(Cells(R, "A"), Cells(R, "U"))
Loop
wbk.Close SaveChanges:=False
FileName = Dir
Loop
With Range("W2", Cells(Rows.count, "W").End(xlUp))
'Chose what to delete before calc. average
.Cells.Find(Application.Max(.Cells), lookat:=xlWhole).ClearContents
'.Cells.Find(Application.Max(.Cells), lookat:=xlWhole).ClearContents
'.Cells.Find(Application.Max(.Cells), lookat:=xlWhole).ClearContents
'.Cells.Find(Application.Min(.Cells), lookat:=xlWhole).ClearContents
'.Cells.Find(Application.Min(.Cells), lookat:=xlWhole).ClearContents
.Cells(.Cells.count).Offset(1, 0) = "=Average(" & .Cells.Address & ")"
End With
'Copy last row from "W" to "V", adjacent to Range("A2:U2") etc. (Not sure this works).
ActiveSheet.Range("V" & Rows.Count).End(xlUp).Offset(1) = ActiveSheet.Range("W" & Rows.Count).End(xlUp)
Bookmarks