find many based on a certain criteria

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
675
Office Version
  1. 365
Platform
  1. Windows
good evening,

I hope someone can help me?

I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet 2 that contains a specific word ( ie Adobe)

This would than display the data on sheet 1. A bit like vlookup, but vlookup as you are aware only picks up one line ...
I need this to display anything with the specific word on sheet 1 row by row.

IE
sheet 1 cell a2 adobe

sheet 2 would then find all the data that contains 'adobe' and display the contents of that row(s) into sheet 1 (a3:z1000)

thank you for your time
KR
Trevor3007
 
Last edited:
Change this Ary = Ws.Range("A1").CurrentRegion.Value2to Ary = Ws.UsedRange.Value2
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
thanks fluff...

sorry am still getting an issue :(
vberror.jpg


see screenshort above.

MTIA
 
Upvote 0
You need to change this line Ary = Ws.Range("A1").CurrentRegion.Value2 to read Ary = Ws.UsedRange.Value2 not add them together.
 
Upvote 0
many thanks...

I hope I have correctly inserted the applicable correctly 9see BOLD txt)?

VBA Code:
Sub Trevor3007()
    Dim Ws As Worksheet
    Dim Ary As Variant, Nary As Variant
    Dim r As Long, c As Long, cc As Long, nr As Long
    Dim Srch As String
    
    Srch = Sheets("search").Range("b1").Value
    If Srch = "" Then Exit Sub
    For Each Ws In Worksheets
        If Ws.Name <> "Search" Then
           [B] Ary = Ws.UsedRange.Value2[/B]
            ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
            
            For r = 2 To UBound(Ary)
                For c = 1 To UBound(Ary, 2)
                    If InStr(1, Ary(r, c), Srch, vbTextCompare) > 0 Then
                        nr = nr + 1
                        For cc = 1 To UBound(Ary, 2)
                            Nary(nr, cc) = Ary(r, cc)
                        Next cc
                        Exit For
                    End If
                Next c
            Next r
            Sheets("search").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(nr, UBound(Ary, 2)).Value = Nary
            nr = 0
        End If
    Next Ws
End Sub

(1) When I run a search with a specific word it returns:-
vberror2.jpg


(2) if i run a search which is on sheet10, it returns:-
vberror3.jpg


It should be that when a search word is placed, that it looks within the wholework book and displays any word that contains the 'search' word , ie *hello*

MTIA
 
Upvote 0
Part of the problem is that soem of your sheets are blank.
Try
VBA Code:
Sub Trevor3007()
    Dim Ws As Worksheet
    Dim Ary As Variant, Nary As Variant
    Dim r As Long, c As Long, cc As Long, nr As Long
    Dim Srch As String
    
    Srch = Sheets("search").Range("b1").Value
    If Srch = "" Then Exit Sub
    For Each Ws In Worksheets
        If Ws.Name <> "Search" Then
            Ary = Ws.UsedRange.Value2
            If Not IsEmpty(Ary) Then
                ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
                For r = 2 To UBound(Ary)
                    For c = 1 To UBound(Ary, 2)
                        If InStr(1, Ary(r, c), Srch, vbTextCompare) > 0 Then
                            nr = nr + 1
                            For cc = 1 To UBound(Ary, 2)
                                Nary(nr, cc) = Ary(r, cc)
                            Next cc
                            Exit For
                        End If
                    Next c
                Next r
            End If
            If nr > 0 Then Sheets("search").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(nr, UBound(Ary, 2)).Value = Nary
            nr = 0
        End If
    Next Ws
End Sub
 
Upvote 0
hi,

nearly there :}

just seems to be the same as issue as before where it does not search all the worksheets (see below)
vberror4.jpg



vberror4_1.jpg
 
Upvote 0
Step through the code using F8 to see where it fails & what the error message & number are.
 
Upvote 0
hi,

presing f8 , highlights each line in yellow, but does NOT bring up a error!!! What happens when you tested it?
 
Upvote 0
It works for me without any problem.
Did you keep stepping through, until the macro finished?
 
Upvote 0
good morning Fluff,

thank you for your ongoing assistance.

I ran the macro & f8, which displays :-
vberror5_1.jpg


this is what search criteria iused:-
vberror5.jpg


link below has the applicable workbook:-

Searchissue191119

hope you can sort & MTIA
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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