Name: Anonymous 2008-10-13 7:53
Hey /prog/
I'm trying to write some VBA code for use in Excel 2007. I have a list of serial numbers and I need to know if they appear _anywhere_ in a multisheet workbook. If possible it should also output the name of the sheet and a link to the cell. Serials to find start in A1 on a new sheet at position 1 and never number more than 100.
Below is my laughable attempt, the idea I had was that after a search if something was found then you'll be on that sheet instead of the one you started on. Currently always reports 'not found'
Sub Macro2()
Dim FindMe As String
Dim StartTab As String
Dim EndTab As String
Dim FoundTab As String
StartTab = ActiveSheet.Name
FindMe = Selection.FormulaR1C1
Range("A1").Select
On Error Resume Next
Cells.Find(What:=FindMe, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
EndTab = ActiveSheet.Name
If StartTab = EndTab Then
FoundTab = "Not found"
Else
FoundTab = EndTab
End If
Sheets(StartTab).Select
Selection.Offset(0, 1).Select
Selection.FormulaR1C1 = FoundTab
Selection.Offset(1, -1).Select 'these move on ready for the next find
End Sub
I'm trying to write some VBA code for use in Excel 2007. I have a list of serial numbers and I need to know if they appear _anywhere_ in a multisheet workbook. If possible it should also output the name of the sheet and a link to the cell. Serials to find start in A1 on a new sheet at position 1 and never number more than 100.
Below is my laughable attempt, the idea I had was that after a search if something was found then you'll be on that sheet instead of the one you started on. Currently always reports 'not found'
Sub Macro2()
Dim FindMe As String
Dim StartTab As String
Dim EndTab As String
Dim FoundTab As String
StartTab = ActiveSheet.Name
FindMe = Selection.FormulaR1C1
Range("A1").Select
On Error Resume Next
Cells.Find(What:=FindMe, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
EndTab = ActiveSheet.Name
If StartTab = EndTab Then
FoundTab = "Not found"
Else
FoundTab = EndTab
End If
Sheets(StartTab).Select
Selection.Offset(0, 1).Select
Selection.FormulaR1C1 = FoundTab
Selection.Offset(1, -1).Select 'these move on ready for the next find
End Sub