run a macro which looks at ranges with added rows

  • Thread starter Thread starter aussiebob
  • Start date Start date
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 ?
 
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
 
Back
Top