run a macro which looks at ranges with added rows

A

aussiebob

I am importing 2 text files into a worksheet and need to update ranges within
the the imported files.
The original macro works fine however when the user imports new text files
the ranges stay the same as when the original macro was created.
looking at the macro in edit mode i see that the original row numbers are
hard coded and do not reflect the additional rows. How can i get the macro to
recognise the additional rows ?
 
G

Gary''s Student

The Recorder will give you something like:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/19/2009 by James Ravenswood
'

'
Range("A1:C11").Select
Selection.ClearContents
End Sub

Clearly the 11 is fixed. You need the code to find the last row if rows are
added:

Sub Macro2()
n = Cells(Rows.Count, "C").End(xlUp).Row
Range("A1:C" & n).ClearContents
End Sub
 

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