Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Neil,
I see that JE gave a looping solution, but in a small dataset, a loop is unnecessary, and does mask the functionality somewhat, IMO. -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Neil" wrote in message ... Thanks Bob, Again another elegant solution - the direct referencing of ranges is a good one to remember instead of copy / paste ops. Cheers. Neil "Bob Phillips" wrote in message ... Try this Sub Transfer_Index_Summary() Application.ScreenUpdating = False totalsheets = Worksheets.Count Range("b5:f16").ClearContents sheetcountno = 4 rowno = 4 ' If sheetcountno = totalsheets Then Exit Sub sheetcountno = sheetcountno + 1 rowno = rowno + 1 With Sheets("Index") .Cells(1, 2).Value = rowno .Cells(2, 2).Value = sheetcounto .Cells(rowno, 2).Value = Sheets(sheetcountno).Cells(27, 2) .Cells(rowno, 3).Value = Sheets(sheetcountno).Cells(2, 15) .Cells(rowno, 4).Value = Sheets(sheetcountno).Cells(2, 5) .Cells(rowno, 5).Value = Sheets(sheetcountno).Cells(3, 5) .Cells(rowno, 6) = Sheets(sheetcountno).Cells(3, 15) End With Application.ScreenUpdating = True End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Neil" wrote in message ... 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 Sub This 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 Sub Now 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Worksheet_Activate | Excel Programming | |||
Can I disable Worksheet_activate??? | Excel Programming | |||
Private Sub Worksheet_Activate() | Excel Programming | |||
Worksheet_Activate | Excel Programming | |||
Worksheet_Activate | Excel Programming |