search a specific cell in multiple tabs and output the name of the tab

chr4and

New Member
Joined
Jun 4, 2024
Messages
5
Office Version
  1. 2019
Platform
  1. MacOS
i want to search within multiple tabs, the value of cell B1, and output the names of the tabs that include a specific value. For example, if tabs k2 and k4 contain the value 1, in cell B1, I want an output as a new sheet, that contains the names k2 and k4.
 
Pls check this



VBA Code:
Sub search_answer()

    Dim ws As Worksheet
    Dim current_ws As Worksheet
    Dim ans As String
    Dim last_row As Long
    Dim i As Long
    Dim j As Long
            
    Set current_ws = ThisWorkbook.Sheets("Answers")' Please change appropriately
   
    ans = "Ans1" 'please change appropriately
         
    lastrow = current_ws.Cells(current_ws.Rows.Count, "A").End(xlUp).Row
   
    lastQ = 10 'change as needed
   
    If Not Evaluate("ISREF('" & ans & "'!A1)") Then Sheets.Add.Name = ans 'checks whether sheet is already there
    'If Evaluate("ISREF('" & ans & "'!A1)") Then ThisWorkbook.Sheets(ans).delete
   
    Set ws = ThisWorkbook.Sheets("Ans1")
   
    'ws.Range("a1").Value = ws.Name
    'MsgBox "The sheet name is: " & ws.Name
    'ws.Range("A1:M20").ClearContents
   
    Start_row = "1"
    Start_col = "A"
    End_row = lastrow
    End_col = lastQ
   
    start_cell = Start_col & Start_row
    end_cell = ws.Cells(End_row, End_col).Address(RowAbsolute:=False, ColumnAbsolute:=False)
   
   
    ws.Range(start_cell & ":" & end_cell).Value = current_ws.Range(start_cell & ":" & end_cell).Value
           
    For j = 2 To lastQ + 1
        For i = 2 To lastrow
       
           If current_ws.Cells(i, j).Value = ans Then
                ws.Cells(i, j) = current_ws.Cells(i, j)
                ws.Range("A1").Name = current_ws.Name
            Else
                ws.Cells(i, j) = 0
            End If
        Next i
    Next j
End Sub
Extremely helpfull. Many thanks!!!
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top