Runtime error - goto

T

Trish Smith

Hi,

I've tried to combine 2 macros that I've used successfully separately.

The first one protects the user interface and the second resets sheets to A2

Private Sub Workbook_Open()

Dim sht As Worksheet

Application.ScreenUpdating = False
For Each sht In Worksheets
Const TopLeft As String = "A2"
sht.Protect Password:="*9reh8", _
UserInterFaceOnly:=True
Application.Goto sht.Range(TopLeft), Scroll:=True

Next sht

Application.ScreenUpdating = True

End Sub

Could anyone tell me where I'm going wrong please

Many thanks
 
G

Gord Dibben

Works fine for me in 2003 and 2007 with no runtime error.

I would suggest qualifying WorkSheets just to be on safe side.

For Each sht In ThisWorkbook.Worksheets

Otherwise.............OK


Gord Dibben MS Excel MVP
 
T

Trish Smith

Hi Frank,

Thanks for replying
I've worked it out - one of my sheets had a merged range at A1:A6.

Thank you
 
T

Trish Smith

Thanks for trying it out Gord.

It was a merged range on one of my sheets. I try to avoid merging cells but
the person I'm doing the workbook for wants a horizontal title over a number
of rows.

I've added rows at the top to get over this.

Thanks again
 
G

Gord Dibben

The person might be satisfied with Center Across Selection which causes no
problems as merged cells do.


Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top