Ex-Lotus Macro User Question on Selecting an 'Unknown' Range


Posted by Gina Kepner on February 04, 2002 5:45 PM

I know you know the answer to this one, given your experience. I used to be able to do lots with Lotus Macros in the old days, but now, I'm at a bit of a loss with VBA. I only understand it at the beginning level.

I have been looking for a way for Excel to loop through a list of data, once I specify the starting point, looking for the last row of the column, and SELECTING the range of data between and including the starting point and the last row. Of course, I mean select in the same way I would mean HIGHLIGHT the data so I can copy it to another area. The copy and paste part isn't a problem, but I've had a heck of a time trying to do this in Excel. In Lotus, with a copy statement first that recorded the first cell and then a period(.) to start the range of copying, and then a loop statement to determine the range with an if statement that checked the current cell for a blank, and if it did not find one, it was told to go {down 1} and go through the loop again, checking for a blank. When it did find the range with a blank in it, it would go {up 1}. Then the {Enter} command in the macro would complete the highlighting of that range. Used to be simple.

How can I do this in Excel with a macro? I know that Excel's macro don't seem to work the same way when it comes to movement within a spreadsheet like Lotus did, and Lotus was so much more easier to understand for a user, than VBA, which is much more complex to learn and much more of a programming language.

I know it should be a snap for you.
Got any ideas?

Gina Kepner



Posted by Derek on February 06, 2002 3:37 AM

Gina
This might help you. It selects from your active cell down to the last entry in that column.

Let x = ActiveCell.Address
Let y = ActiveCell.Row

ActiveCell.Offset(65536 - y, 0).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveCell.Select
Range(x, ActiveCell).Select
End Sub

Good luck
Derek