delete range using VBA

W

Wanna Learn

Hello
I get a daily report from an outside vendor which I copy and paste into my
report.
On columns AH and AI, I have added formulas to determine if the payment is
late and the amount due
I want to delete the range starting in row 5 to column AG till the last row
that has information. I do not want to delete the formulas on column AH
and AI so they will calculate. I tried
Sub Clear141()
'
' Clear141 Macro

'
Range("A5:AG3424" & Count).Select
Selection.ClearContents
End Sub
This seems to work but is it the best way to do it.
thanks
 
M

Mike H

Hi,

As a general rule there is rarely; if ever, any need to select a range to do
something and not necessary in this case. Try this

Sub Clear141()
Dim LastRow as Long
lastrow = Cells(Cells.Rows.Count, "AG").End(xlUp).Row
Range("A5:AG" & lastrow).ClearContents
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top