Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Runtime error - goto

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
--
Trish
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Runtime error - goto

Try moving the line Const TopLeft as String="A2" to just below the Dim sht line
--
Frank K


"Trish Smith" wrote:

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
--
Trish

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Runtime error - goto

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


On Sat, 12 Dec 2009 13:34:01 -0800, Trish Smith
wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Runtime error - goto

Hi Frank,

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

Thank you

--
Trish


"Frank K" wrote:

Try moving the line Const TopLeft as String="A2" to just below the Dim sht line
--
Frank K


"Trish Smith" wrote:

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
--
Trish

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Runtime error - goto

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
--
Trish


"Gord Dibben" wrote:

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


On Sat, 12 Dec 2009 13:34:01 -0800, Trish Smith
wrote:

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


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Runtime error - goto

You gotta love those merged cells<g


Gord

On Sat, 12 Dec 2009 17:12:01 -0800, Trish Smith
wrote:

Hi Frank,

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

Thank you


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Runtime error - goto

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


Gord

On Sat, 12 Dec 2009 17:16:01 -0800, Trish Smith
wrote:

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resetting error reporting after On Error GoTo Steve Excel Programming 1 August 14th 09 05:24 AM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
On Error Goto doesn't goto Paul Excel Programming 1 October 15th 04 03:51 PM
On Error Goto doesn't goto Paul Excel Programming 0 October 15th 04 03:05 PM
On error goto 0? Brian Tozer Excel Programming 10 December 29th 03 09:59 PM


All times are GMT +1. The time now is 03:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"