View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
excelent excelent is offline
external usenet poster
 
Posts: 695
Default Returning last columns with no values in (but possibly w. formulas

=MAX(IF(1:1<"",COLUMN(1:1))+1)

insert and type CTRL+SHIFT+ENTER

return last column in row 1

"Kragelund" skrev:

I picked up the following code from a previous thread. The code selects the
last column that has formulas in it. How do I modify the code to select the
last column, which has no values in it (but may still have code in that
returns ""). I need it for dimensioning the size of a print area, which
should obviously not include empty cells.

Thanks!

Kragelund


Public Sub test()
Cells(1, LastColumn()).Select
End Sub

Public Function LastColumn(Optional wks As Worksheet) As Integer
If wks Is Nothing Then Set wks = ActiveSheet
LastColumn = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
End Function