ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Finding the last cell in a protected sheet (https://www.excelbanter.com/excel-programming/375712-finding-last-cell-protected-sheet.html)

TishyMouse

Finding the last cell in a protected sheet
 
The command:

SpecialCells(xlLastCell).Select

fails if my worksheet is protected. Is there any way round this without
resorting to unprotecting the sheet (I don't want to have to hard code the
password in my macro)?

Thanks

TM

TishyMouse

Finding the last cell in a protected sheet
 
Oh it's OK, just found the answer in the archive :-) Duh!

myLastCol = _
..Cells.Find("*", After:=.Cells(1), _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

Thanks anyway

TM

"TishyMouse" wrote:

The command:

SpecialCells(xlLastCell).Select

fails if my worksheet is protected. Is there any way round this without
resorting to unprotecting the sheet (I don't want to have to hard code the
password in my macro)?

Thanks

TM


Tom Ogilvy

Finding the last cell in a protected sheet
 
mylastCol = cells.specialcells(xlLastcell).Column

--
Regards,
Tom Ogilvy




"TishyMouse" wrote:

Oh it's OK, just found the answer in the archive :-) Duh!

myLastCol = _
.Cells.Find("*", After:=.Cells(1), _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

Thanks anyway

TM

"TishyMouse" wrote:

The command:

SpecialCells(xlLastCell).Select

fails if my worksheet is protected. Is there any way round this without
resorting to unprotecting the sheet (I don't want to have to hard code the
password in my macro)?

Thanks

TM


TishyMouse

Finding the last cell in a protected sheet
 
THanks, Tom, but that is the command that I was trying originally doesn't
seem to work on a protected sheet.

The 'find' method works fine, it's just a bit longer.

"Tom Ogilvy" wrote:

mylastCol = cells.specialcells(xlLastcell).Column

--
Regards,
Tom Ogilvy




"TishyMouse" wrote:

Oh it's OK, just found the answer in the archive :-) Duh!

myLastCol = _
.Cells.Find("*", After:=.Cells(1), _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

Thanks anyway

TM

"TishyMouse" wrote:

The command:

SpecialCells(xlLastCell).Select

fails if my worksheet is protected. Is there any way round this without
resorting to unprotecting the sheet (I don't want to have to hard code the
password in my macro)?

Thanks

TM


Tom Ogilvy

Finding the last cell in a protected sheet
 
Sub ABC()
ActiveSheet.Protect UserInterfaceOnly:=True
Set rng = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell)
lastcol = rng.Column
MsgBox lastcol
End Sub

worked fine for me on a protected sheet. If it is password protected, in
xl2002 and later you would have to supply the password.

--
Regards,
Tom Ogilvy


"TishyMouse" wrote:

THanks, Tom, but that is the command that I was trying originally doesn't
seem to work on a protected sheet.

The 'find' method works fine, it's just a bit longer.

"Tom Ogilvy" wrote:

mylastCol = cells.specialcells(xlLastcell).Column

--
Regards,
Tom Ogilvy




"TishyMouse" wrote:

Oh it's OK, just found the answer in the archive :-) Duh!

myLastCol = _
.Cells.Find("*", After:=.Cells(1), _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

Thanks anyway

TM

"TishyMouse" wrote:

The command:

SpecialCells(xlLastCell).Select

fails if my worksheet is protected. Is there any way round this without
resorting to unprotecting the sheet (I don't want to have to hard code the
password in my macro)?

Thanks

TM



All times are GMT +1. The time now is 04:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com