ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   run a macro which looks at ranges with added rows (https://www.excelbanter.com/new-users-excel/221566-run-macro-looks-ranges-added-rows.html)

aussiebob

run a macro which looks at ranges with added rows
 
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 ?

Gary''s Student

run a macro which looks at ranges with added 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

--
Gary''s Student - gsnu200834


"aussiebob" wrote:

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 ?



All times are GMT +1. The time now is 10:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com