Try this - I didn't actually put the formulas in the cells, just the results. Let me know if you actually want the formulas 
Sub test()
Dim lr&, i&, x&, accnum$
lr = Range("E65536").End(xlUp).Row
For i = lr To 1 Step -1
If Cells(i, 5).Value = "0" Then
If Cells(i, 4).Value = "BEGINNING BALANCE" Then GoTo nxt
If Cells(i, 4).Value <> "" Then Cells(i, 4).EntireRow.Delete: GoTo nxt
If Cells(i, 2).Value = "Subtotal" Then
x = 1
Do Until Cells(i - x, 2).Value = "Account Number"
x = x + 1
Loop
Range(Cells(i - x - 1, 1), Cells(i, 1)).EntireRow.Delete
End If
nxt:
End If
Next i
For Each cell In Range("D1:D" & Range("D65536").End(xlUp).Row)
If cell.Value = "BEGINNING BALANCE" Then
accnum = cell.Offset(-4, -2).Value
x = 0
Do Until cell.Offset(x, 0).Value = ""
cell.Offset(x, 2).Value = accnum
cell.Offset(x, 3).NumberFormat = "dd/mm/yyyy"
If cell.Offset(x, -2) = "" Then
cell.Offset(x, 3).Value = "7/1/2012"
Else
cell.Offset(x, 3).Value = WorksheetFunction.EoMonth(cell.Offset(x, -2).Value, 0)
End If
cell.Offset(x, 4).NumberFormat = "@"
cell.Offset(x, 4).Value = Mid(accnum, 8, 4)
cell.Offset(x, 5).NumberFormat = "@"
cell.Offset(x, 5).Value = Mid(accnum, 16, 3)
x = x + 1
Loop
End If
Next
End Sub
Please click the * below if this helps
Bookmarks