ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Bringing focus back to source point upon subroutine run completion (https://www.excelbanter.com/excel-programming/298769-bringing-focus-back-source-point-upon-subroutine-run-completion.html)

Max

Bringing focus back to source point upon subroutine run completion
 
Hi guys,

Let's say I'm working in Sheet13 with cursor on B3

Using Alt+F8, I call / run a sub from my personal.xls, for example:

Sub SwitchOffGridLinesWS()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
Next
End Sub

The sub finishes its job but the activesheet has changed
to the rightmost sheet's cell A1

How do I bring the cursor focus back to where I was when I ran the sub:
i.e. back to Sheet13 with cursor on B3 ?

Thanks for insights.
--
Rgds
Max
xl 97
---
Please respond, in newsgroup
xdemechanik <atyahoo<dotcom
----



[email protected]

Bringing focus back to source point upon subroutine run completion
 
Sub SwitchOffGridLinesWS()
Dim ws As Worksheet
Dim wsht as Worksheet
Set wsht=activesheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
Next
wsht.select
End Sub

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------

Hi guys,

Let's say I'm working in Sheet13 with cursor on B3

Using Alt+F8, I call / run a sub from my personal.xls, for example:

Sub SwitchOffGridLinesWS()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
Next
End Sub

The sub finishes its job but the activesheet has changed
to the rightmost sheet's cell A1

How do I bring the cursor focus back to where I was when I ran the sub:
i.e. back to Sheet13 with cursor on B3 ?

Thanks for insights.



Chris

Bringing focus back to source point upon subroutine run completion
 
Here is one way
Sub SwitchOffGridLinesWS()
Dim ws As Worksheet, MyWs as Worksheet, MyRng as Rang
Set MyWs as ActiveShee
Set MyRng = Selectio
For Each ws In ActiveWorkbook.Worksheet
ws.Activat
ActiveWindow.DisplayGridlines = Fals
Nex
MyWs.Activat
MyRng.Selec
End Su


----- Max wrote: ----

Hi guys

Let's say I'm working in Sheet13 with cursor on B

Using Alt+F8, I call / run a sub from my personal.xls, for example

Sub SwitchOffGridLinesWS(
Dim ws As Workshee
For Each ws In ActiveWorkbook.Worksheet
ws.Activat
ActiveWindow.DisplayGridlines = Fals
Nex
End Su

The sub finishes its job but the activesheet has change
to the rightmost sheet's cell A

How do I bring the cursor focus back to where I was when I ran the sub
i.e. back to Sheet13 with cursor on B3

Thanks for insights
-
Rgd
Ma
xl 9
--
Please respond, in newsgrou
xdemechanik <atyahoo<dotco
---




chris: Correction

Bringing focus back to source point upon subroutine run completion
 


----- chris wrote: ----

Here is one way
Sub SwitchOffGridLinesWS()
Dim ws As Worksheet, MyWs as Worksheet, MyRng as Rang
Set MyWs = ActiveShee
Set MyRng = Selectio
For Each ws In ActiveWorkbook.Worksheet
ws.Activat
ActiveWindow.DisplayGridlines = Fals
Nex
MyWs.Activat
MyRng.Selec
End Su



----- Max wrote: ----

Hi guys

Let's say I'm working in Sheet13 with cursor on B

Using Alt+F8, I call / run a sub from my personal.xls, for example

Sub SwitchOffGridLinesWS(
Dim ws As Workshee
For Each ws In ActiveWorkbook.Worksheet
ws.Activat
ActiveWindow.DisplayGridlines = Fals
Nex
End Su

The sub finishes its job but the activesheet has change
to the rightmost sheet's cell A

How do I bring the cursor focus back to where I was when I ran the sub
i.e. back to Sheet13 with cursor on B3

Thanks for insights
-
Rgd
Ma
xl 9
--
Please respond, in newsgrou
xdemechanik <atyahoo<dotco
---




Max

Bringing focus back to source point upon subroutine run completion
 
Thanks, Paul !
Works great.
--
Rgds
Max
xl 97
---
Please respond, in newsgroup
xdemechanik <atyahoo<dotcom
----
wrote in message
...
Sub SwitchOffGridLinesWS()
Dim ws As Worksheet
Dim wsht as Worksheet
Set wsht=activesheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
Next
wsht.select
End Sub

HTH
Paul




Max

Bringing focus back to source point upon subroutine run completion
 
Thanks, Chris !
Works great ..
--
Rgds
Max
xl 97
---
Please respond, in newsgroup
xdemechanik <atyahoo<dotcom
----
"chris: correction" wrote in message
...


----- chris wrote: -----

Here is one way:
Sub SwitchOffGridLinesWS()
Dim ws As Worksheet, MyWs as Worksheet, MyRng as Range
Set MyWs = ActiveSheet
Set MyRng = Selection
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
ActiveWindow.DisplayGridlines = False
Next
MyWs.Activate
MyRng.Select
End Sub





All times are GMT +1. The time now is 11:20 AM.

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