Sorting rows with macro

R

Raymond

I have a macro which imports a .htm file from another application then sorts the rows,

The problem is that the number of rows in the import file varies. In writing the macro I use ctrl downarrow to select the last cell in the column, select that cell - scroll to the top select the range. Even though I used ctrl keys to select the range Excel takes the values as absolute

How can I make the Range selection relative. First cell to last cell regardless of the length of the file
 
B

Bob Phillips

Raymond,

You can calculate the number of rows as follows

Cells(Rows.Count,"A").End(xlUp).Row

which checks down column. The range can be calculated as

rng = Range("A1", "H" & Cells(Rows.Count,"A").End(xlUp).Row)

obviously change the columns to suit

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

Raymond said:
I have a macro which imports a .htm file from another application then sorts the rows,.

The problem is that the number of rows in the import file varies. In
writing the macro I use ctrl downarrow to select the last cell in the
column, select that cell - scroll to the top select the range. Even though I
used ctrl keys to select the range Excel takes the values as absolute.
How can I make the Range selection relative. First cell to last cell
regardless of the length of the file.
 
Top