View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
david mcritchie david mcritchie is offline
external usenet poster
 
Posts: 691
Default Problem with Worksheet collections... :(

correction on the macro
I left out the period before name in a couple of statements
and I presume "Top" sheet and "Bottom" were not to be
processed so made some changesfor that as well.
If LCase(wkSheet.Name) = "top" Then


Sub abxy()
Dim C As String, i As Long, flag As Long '2004-05-11
Dim wkSheet As Worksheet, curSheet As Worksheet
'Create New Sheet
Sheets.Add After:=Sheets(Sheets.Count) '-- place at end
'Rename current Sheet (the new sheet)
ActiveSheet.Name = "D" & Format(Now(), "yyyy_mmdd_mmss")
'save name of current sheet
Set curSheet = ActiveSheet
i = 1 'skip top row for your headers
Range("A1:D1") = Array("Sheet Name", "A1", "B1", "C1", "textbox1")
Rows("1:1").Font.Bold = True
flag = 0
For Each wkSheet In Application.Worksheets
If LCase(wkSheet.Name) = "top" Then
flag = 1
GoTo bypass
End If
If LCase(wkSheet.Name) = "bottom" Then flag = 0
If wkSheet.Name = curSheet.Name Then GoTo bypass
If flag = 0 Then GoTo bypass '-- activate if you have a top and bottom sheet
i = i + 1
'ooo--- your code here ----ooo
'MsgBox " -- " & wkSheet.Name
Cells(i, 1) = wkSheet.Name
Cells(i, 2) = wkSheet.Cells(1, 1).Text
Cells(i, 3) = wkSheet.Cells(1, 2).Text
With wkSheet.Range("A1:A275")
' On Error Resume Next
'------ this is your code -------
'-- Set C = .Find(What:=Right("0000000" & textbox1.Value, 7), _
'-- lookat:=xlWhole)
'-- Cells(i, 4) = C
' On Error GoTo 0
End With
bypass:
Next wkSheet
If i = 0 Then MsgBox "Top Sheet is missing, or was last sheet"
End Sub

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm