I just want to insert 3 rows with formulas but these rows keep inserting over and over again in the first opened workbook.
For the sake of discussion, would it be better to use a For Each loop instead?
Sub FXBuy()
Dim wb As Workbook
Dim PathName$, FileName$
PathName = "H:\BASEL Reporting - Oliver's Mock\FX\"
FileName = Dir(PathName)
Do While FileName <> ""
Set wb = Workbooks.Open(PathName & FileName)
wb.Sheets("FX").Columns("W:X").Hidden = True
wb.Sheets("FX").Columns("AD:AI").Hidden = True
wb.Sheets("FX").Columns("U:AB").SpecialCells(xlCellTypeVisible).Interior.Color = 65535
LastRow = wb.Sheets("FX").Columns("B").Find("B", LookAt:=xlPart).MergeArea.Row + wb.Sheets("FX").Columns("B").Find("B", LookAt:=xlPart).MergeArea.Rows.Count - 1
wb.Sheets("FX").Range("A" & LastRow & ":A" & LastRow + 2).EntireRow.Insert
wb.Sheets("FX").Range("S" & LastRow) = 20
wb.Sheets("FX").Range("S" & LastRow + 1) = 50
wb.Sheets("FX").Range("U" & LastRow).Formula = "=SUMIF($K$3:$K$" & LastRow - 1 & ",0.2,U$3:U$" & LastRow - 1 & ")"
wb.Sheets("FX").Range("Z" & LastRow).Formula = "=SUMIF($K$3:$K$" & LastRow - 1 & ",0.2,Z$3:Z$" & LastRow - 1 & ")"
wb.Sheets("FX").Range("AB" & LastRow).Formula = "=SUMIF($K$3:$K$" & LastRow - 1 & ",0.2,AB$3:AB$" & LastRow - 1 & ")"
wb.Sheets("FX").Range("U" & LastRow + 1).Formula = "=SUMIF($K$3:$K$" & LastRow - 1 & ",0.5,U$3:U$" & LastRow - 1 & ")"
wb.Sheets("FX").Range("Z" & LastRow + 1).Formula = "=SUMIF($K$3:$K$" & LastRow - 1 & ",0.5,Z$3:Z$" & LastRow - 1 & ")"
wb.Sheets("FX").Range("AB" & LastRow + 1).Formula = "=SUMIF($K$3:$K$" & LastRow - 1 & ",0.5,AB$3:AB$" & LastRow - 1 & ")"
wb.Sheets("FX").Range("U" & LastRow + 2).Formula = "=SUM(U" & LastRow & ",U" & LastRow + 1 & ")"
wb.Sheets("FX").Range("Z" & LastRow + 2).Formula = "=SUM(Z" & LastRow & ",Z" & LastRow + 1 & ")"
wb.Sheets("FX").Range("AB" & LastRow + 2).Formula = "=SUM(AB" & LastRow & ",AB" & LastRow + 1 & ")"
Loop
End Sub