LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Worksheet_Activate - conditional use

Hi All,

I have utilised the Worksheets Index macro from ozgrid.com as follows:

Private Sub Worksheet_Activate()
Dim wSheet As Worksheet
Dim l As Long
l = 1

With Me
.Columns(1).ClearContents
.Cells(1, 1) = "INDEX"
.Cells(1, 1).Name = "Index"
End With

For Each wSheet In Worksheets
If wSheet.Name < Me.Name Then
l = l + 1
With wSheet
.Range("A1").Name = "Start " & wSheet.Index
.Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
SubAddress:="Index", TextToDisplay:="Back to Index"
End With

Me.Hyperlinks.Add Anchor:=Me.Cells(l, 1), Address:="", _
SubAddress:="Start " & wSheet.Index, TextToDisplay:=wSheet.Name
End If
Next wSheet
End SubThis is a great macro that auto updates and builds a TOC every time I open (activate) the "Index" sheet.Unfortunately I'd like to also be able to run another macro (manually, press 'button') from within this worksheet.The macro cycles through the available worksheets in the workbook and copies across data, thus creating a summary of key fields in my worksheets, as follows:Sub Transfer_Index_Summary()'' Transfer_Index_Summary Macro' Macro recorded 3/07/2007 by Neil'Application.ScreenUpdating = Falsetotalsheets = Worksheets.CountRange("b5:f16").ClearContentssheet countno = 4rowno = 4'DoIf sheetcountno = totalsheets ThenExit SubElsesheetcountno = sheetcountno + 1rowno = rowno + 1 Sheets(sheetcountno).Select Cells(27, 2).Select Selection.Copy Sheets("Index").Select Cells(1, 2).Value = rowno Cells(2, 2).Value = sheetcountno Cells(rowno, 2).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets(sheetcountno).Select Cells(2, 15).Select Application.CutCopyMode = False Selection.Copy Sheets("Index").Select Cells(rowno, 3).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets(sheetcountno).Select Cells(2, 5).Select Application.CutCopyMode = False Selection.Copy Sheets("Index").Select Cells(rowno, 4).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets(sheetcountno).Select Cells(3, 5).Select Application.CutCopyMode = False Selection.Copy Sheets("Index").Select Cells(rowno, 5).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets(sheetcountno).Select Cells(3, 15).Select Application.CutCopyMode = False Selection.Copy Sheets("Index").Select Cells(rowno, 6).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False End If Loop'Application.EnableEvents = True End SubNow here's the problem, as soon as my manual code is run and gets to the line Sheets("Index").Selectit runs the Worksheet_Activate code and hence the (manual) code crashes when it can't paste the data to the sheet.Is there some way I can either combine these two macros (more elegantly hopefully) or otherwise halt the running of the auto macro until I have successfully run the manual macro ?Your help ( as always) is greatly appreciated.Regards,Neil
 
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
Worksheet_Activate greg Excel Programming 2 September 26th 06 01:24 PM
Can I disable Worksheet_activate??? broogle Excel Programming 3 June 29th 05 10:15 AM
Private Sub Worksheet_Activate() Teodor Bobochikov Excel Programming 1 September 28th 04 11:03 AM
Worksheet_Activate Pozzo Excel Programming 5 June 7th 04 07:39 PM
Worksheet_Activate Jim Carlock[_2_] Excel Programming 2 September 25th 03 12:47 AM


All times are GMT +1. The time now is 04:29 PM.

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

About Us

"It's about Microsoft Excel"