• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

deleting cells with formula

HanSam

Member
Code:
output.Range("BF2").AutoFill destination:=output.Range("BF2:BF" & Cells(Rows.Count, "H").End(xlUp).Row)

The code above looks up to Column H and autofills Column BF with formula up to Rows of Column H that has value. This code is triggered by another code which fills up Column H. If for example Column H had 1000 rows, Column BF will have 1000 rows as well with formulas.

If, Column H had lesser rows on the next fill up - the 1000 rows of BF will still have the formulas. Is there any way to remove these formulas through VBA?
 
You can delete all cells in column BF which are not required.
Code:
output.Range("BF2").AutoFill Destination:=output.Range("BF2:BF" & Cells(Rows.Count, "H").End(xlUp).Row)
Dim lnglastrow As Long
lnglastrow = Range("BF:BF").Find("*", , xlFormulas, , , xlPrevious).Row
If lnglastrow > Cells(Rows.Count, "H").End(xlUp).Row Then
    output.Range("BF" & Cells(Rows.Count, "H").End(xlUp).Row + 1 & ":O" & lnglastrow).Delete xlUp
End If
 
Back
Top