PDA

View Full Version : Solved: Finding the last empty column in a row?



nathan2314
10-29-2010, 02:27 PM
Hi
How can I find the last empty column in a row. I need to find the last row and also the last column in that row so I can paste data all in one row. In the code below, it works for finding the last row, but the column part doesn't work. It gives an error. I tried using End(xlleft) and .End(xlRight) but those give an error that says "400". .End(xlup) and .End(xldown) work fine.

Appreciate any help!


endrow_d = basebook.Sheets("raw data").Cells(65536, 1).End(xlUp).Row + 1

endcol_d = basebook.Sheets("raw data").Cells(endrow_d, 100).End(xlLeft)

Bob Phillips
10-29-2010, 04:17 PM
endcol_d = basebook.Sheets("raw data").Cells(endrow_d, Columns.Count).End(xlToLeft).Column

Kenneth Hobs
10-30-2010, 11:07 AM
XLD's finds the last with data. Just add 1 or use Offset.
endcol_d = basebook.Sheets("raw data").Cells(endrow_d, Columns.Count).End(xlToLeft).Column+1

nathan2314
11-01-2010, 07:20 AM
Great!! Thanks! That worked perfect!