View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Last Column With Data

You could use:

..range("b1",.cells(1,lastcol)).entirecolumn.Autof it
or
..range("b1",.columns(lastcol)).entirecolumn.autof it



Bishop wrote:

This gives a interger value but I can't make it work with this statement:

.Columns("B:" & LastCol).EntireColumn.AutoFit

Do I need to set LastCol as something other than Long? Or is there a
different syntax I should use to make the above statement work?

"Dave Peterson" wrote:

Dim myRow as long
dim LastCol as long

myrow = 1243

with worksheets("SomeSheetnamehere")
lastcol = .cells(myrow,.columns.count).end(xltoleft).column
end with

msgbox LastCol

This will break if you've used the last column in that row -- or if you haven't
used any cells in that row.

Is that a problem?



Bishop wrote:

How do I check a certain row to find out the last column in the row that has
data?


--

Dave Peterson
.


--

Dave Peterson