Finding last items in a list

  • Thread starter Thread starter b_whittle
  • Start date Start date
B

b_whittle

Hi,

I am trying to write a macro to automate some data extraction from a
text file. My text file consists of three columns of numbers. The
number of lines of data varies from file to file.

I would like to use the 'slope' function to do a regression on the
last 20 lines of data but I am getting confused about how to specify
that range in the formula since the range will be different in every
text file I have.

Yell at me if I'm not making myself clear. Hope someone can help me

thanks
Ben
 
Hi Ben,

A clumsy but effective method I use is to select the top cell in the last
(rightmost)column of data and then do Selection.End(xlDown).Select (same as
CTRL +DownArrow) on the keyboard - assuming there are no gaps in the data,
this will select the bottom cell in the column. You can then do
Range(Selection, Selection.Offset(-20, -xxx)).Select where xxx is the number
of columns to the left you want to select.

If there may be gaps in the data, then go to a cell below the last entry in
the in the rightmost column (e.g.65535) and then do
Selection.End(xlUp).Select (Same as CTRL+UpArrow on the keyboard.

Regards,

Z
 
Teriffic. That does what I need. I used:

Range(Selection, Selection.Offset(-20, -xxx)).name = "lastcells"

to name the group of cells so I could reference it in the funciton.

thanks
Ben
 

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

Back
Top