last column with data


Posted by David Rainey on July 05, 2001 11:04 AM

I had a question about an old post.

19241.html

(2)
Cells(65536, x + 1).End(xlUp).Select
I want to find the last cell in a row that has data

For x = 1 To Cells(Target.Row, 9000).End(xlLeft).Column
strChangedRow(x) = Cells(Target.Row, x)
Next

but I always get an run time error 1004
application defined or object defined error

also this is in the routine
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Posted by Joe Was on July 05, 2001 12:13 PM

You should run this type of code from a module not a from a Sheet-Tab, View Code macro.
Also, try : Range("B65536").End(xlUp).Select
Where, "B" is the column you want to look for data in. The code moves up from the bottom to the first ROW it finds data in and selects it. You must then do something with it?

The code above will in affect give you the last ROW that has data. This code works well if you know that the data you are looking for will be in a known COLUMN?

The loop code from your test code is slow, if the above condition is known. If you don't know what COLUMN your data will be in then the loop is as good as any?

You could modify the code to look for the ROW ADDRESS of the first found data cell going up as well and Select it? JSW

Posted by David Rainey on July 05, 2001 2:13 PM


I want to find the last cell in a row not in a column

Posted by Joe Was on July 05, 2001 8:09 PM

Try: myRange.End(xlToLeft).Select
where "myRange" is the range you want to check. The other code works, it gives you the first ROW from the bottom that has data, if you know the column?

Do you want the Column from "IV" to "A" that has data in a Row?

Or, Do you want to select the cell which has the highest Row number in a Column, whos cell has data?

Or, Do you want to select the Right most column that has a Row cell with data?

Or, Do you want to select the bottom Row with data regardless of Column?

Your Msg is un-clear? JSW



Posted by David Rainey on July 09, 2001 12:38 PM

I was having a problem because I was using xlleft
instead of xltoleft

I am good now Try: myRange.End(xlToLeft).Select