Hide rows that contain two strings or numbers in a cell

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I am having issues with getting a task accomplished.
I have found some scripts on the net but they all seem to get me just half way through the journey. They could find just one string .

In a column say column C, I have data in the form 00-01-02-03-04 and I want to find two of the sub stings either from values in two cells or an InputBox (whichever is cool). Say "00" and "03" (Both must be located not just one). I am not sure how excel is treating those 00 and 03 etc so I am using "string" .

So when those matches are found, hide all rows except those matched.

Else display a message box "No Match Found"

I just hope this is achievable.

Thanks in advance
Kelly
 
Okay just found out what's happening :

The insertion point must must always be in column A since we're copying entire rows .

How do I get that always in cell A1?

Resolved

Sheets("Sheet3").Range("A1").select
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Code:
Sub AnotherLoop_1063452()
Dim r As Range, rng As Range, rng1 As Range, b As Boolean
Dim arr As Variant
Application.ScreenUpdating = False

Set rng = Range("C1:C" & Cells(Rows.Count, "C").End(xlUp).Row)
b = False
arr = Split(Application.InputBox("Please enter two 2-digit numbers separated by a comma."), ",")
If UBound(arr) <> 1 Then
    MsgBox "Your entry is invalid. Please try again."
    Exit Sub
End If

For Each r In rng
    If InStr(r.Value, arr(0)) > 0 And InStr(r.Value, arr(1)) > 0 Then
        b = True
        On Error GoTo nxt
        Set rng1 = Application.Union(rng1, r)
    End If
Next r
If b = True Then
'    rng.Rows.Hidden = True
'    rng1.EntireRow.Hidden = False
'    ActiveWindow.ScrollRow = rng1.Row
    rng1.EntireRow.Copy
    Sheets.Add after:=Sheets(Sheets.Count)
    ActiveSheet.Paste
Else
    MsgBox "No match found."
End If

Exit Sub
nxt:
    Set rng1 = r
    On Error GoTo 0
    Resume Next
End Sub


Hello
Hello tonyyy,

One last question :

How do I search for just one number?

Regards
Kelly
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

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