Question : Excel Macro/VB to search multiple worksheets

Hello Everybody,

I need some help on Excel Macro/VB script

Following is my requirement

I have a excel workbook with 7 worksheets, worksheets 1-6 to have some numbers.

Worksheet 7 has list of numbers which may or may not be in worksheets 1-6.

I want to write a VB/macro code, where in it takes up a particular column in sheet 7 as input to search and search for that numbers in sheet 1-6

If the search result is true then update the sheet 7 with location of the search result and if not found then highlight the cell in sheet 7 with some colour.

Any help on this appreciated.

Answer : Excel Macro/VB to search multiple worksheets

Hi there, try this macro.

This assumes that "Sheet 7" is the last sheet in your workbook, and you want to search all other worksheets.

Change strColumn to the colum in Sheet 7 that has the numbers to search for.
Change intStartRow to the row number on Sheet 7 where the numbers start.
Make sure you have a blank column for the results on the right hand side of the column with the numbers.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
Sub FindNumbers()
    strColumn = "A"
    intStartRow = 1
    Set objLastSheet = Sheets(Sheets.Count)
    For intRow = intStartRow To objLastSheet.Cells(65536, strColumn).End(xlUp).Row
        strValue = objLastSheet.Cells(intRow, strColumn).Value
        strFoundSheet = ""
        For intSheet = 1 To Sheets.Count - 1
            Sheets(intSheet).Activate
            Set objCell = Cells.Find(What:=strValue, After:=Sheets(intSheet).Cells(1, 1), LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
            If Not objCell Is Nothing Then
                strFoundSheet = Sheets(intSheet).Name
                Exit For
            End If
        Next
        If strFoundSheet <> "" Then
            objLastSheet.Cells(intRow, strColumn).Offset(0, 1).Value = strFoundSheet
        Else
            objLastSheet.Cells(intRow, strColumn).Offset(0, 1).Interior.Color = 255
        End If
    Next
    objLastSheet.Activate
End Sub
Random Solutions  
 
programming4us programming4us