ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook_SheetSelectionChange in going infinite (https://www.excelbanter.com/excel-programming/383437-workbook_sheetselectionchange-going-infinite.html)

sency

Workbook_SheetSelectionChange in going infinite
 
I am calling a macro from Workbook_SheetSelectionChange() where in i am using
something like :
lastCol = ws.Range("A1:IV1").cells.SpecialCells(xlLastCell). Column which
goes back to my Workbook_SheetSelectionChange() routine again, effecting an
infinite loop. How can i proceed with this code? How can i stop it from going
back to Workbook_SheetSelectionChange() whenever i make a range selection??

thanks in advance, Sency.

Jim Thomlinson

Workbook_SheetSelectionChange in going infinite
 
The line you posted will not cause the loop, but a selection will. Normally
you can avoid selecting cells by using range objects and such but you can
turn off events if that is the course you want to follow. Try something like
this. Note it is a good idea to use an error handler with this type of code...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrorHandler
Application.EnableEvents = False
'your code here
ErrorHandler:
Application.EnableEvents = True
End Sub
--
HTH...

Jim Thomlinson


"sency" wrote:

I am calling a macro from Workbook_SheetSelectionChange() where in i am using
something like :
lastCol = ws.Range("A1:IV1").cells.SpecialCells(xlLastCell). Column which
goes back to my Workbook_SheetSelectionChange() routine again, effecting an
infinite loop. How can i proceed with this code? How can i stop it from going
back to Workbook_SheetSelectionChange() whenever i make a range selection??

thanks in advance, Sency.


sency

Workbook_SheetSelectionChange in going infinite
 
Hi,
thanks for your time.

anyways, i solved this by moving the macro call from
Workbook_SheetSelectionChange() to Worksheet_SelectionChange().

"sency" wrote:

I am calling a macro from Workbook_SheetSelectionChange() where in i am using
something like :
lastCol = ws.Range("A1:IV1").cells.SpecialCells(xlLastCell). Column which
goes back to my Workbook_SheetSelectionChange() routine again, effecting an
infinite loop. How can i proceed with this code? How can i stop it from going
back to Workbook_SheetSelectionChange() whenever i make a range selection??

thanks in advance, Sency.



All times are GMT +1. The time now is 01:54 AM.

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