How select rows on multiple cells determined by textbox find

Releeuw46

New Member
Joined
Aug 19, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I could use some help with getting the VBA on the following.

I have a large range of data, blanks, and multiple duplicate cell values.
I need to find (select) matching cell or cells , and then select the rows of those found cells. Not highlighted, just select.

My search value is in ( "B2" ), Partial text search.

I already got this but cat get the rows s;ected

Private Sub CommandButton1_Click()

Dim Partial_Text As String
Dim Myrange As Range
Partial_Text = Worksheets("2022").Cells(2, 2).Value

Set Myrange = Worksheets("2022").Range("B3:AC500")
For Each cell In Myrange

If InStr(LCase(cell.Value), LCase(Partial_Text)) <> 0 Then
ActiveCell.EntireRow.Select ('Here it fails...)

End If
Next

End Sub

Thanks,
René
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
VBA Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim i&, j&
Dim Partial_Text As String
Dim Myrange, u As Range
With Worksheets("2022")
    Partial_Text = .Cells(2, 2).Value
    Myrange = Worksheets("2022").Range("B3:AC500").Value
    On Error Resume Next
    For i = 1 To UBound(Myrange)
        For j = 1 To UBound(Myrange, 2)
            If LCase(Myrange(i, j)) Like "*" & LCase(Partial_Text) & "*" Then
                If u Is Nothing Then
                    Set u = Rows(i + 2)
                Else
                    Set u = Union(u, Rows(i + 2))
                End If
                Exit For
            End If
        Next
    Next
    u.Select
End With
End Sub
 
Upvote 0
VBA Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim i&, j&
Dim Partial_Text As String
Dim Myrange, u As Range
With Worksheets("2022")
    Partial_Text = .Cells(2, 2).Value
    Myrange = Worksheets("2022").Range("B3:AC500").Value
    On Error Resume Next
    For i = 1 To UBound(Myrange)
        For j = 1 To UBound(Myrange, 2)
            If LCase(Myrange(i, j)) Like "*" & LCase(Partial_Text) & "*" Then
                If u Is Nothing Then
                    Set u = Rows(i + 2)
                Else
                    Set u = Union(u, Rows(i + 2))
                End If
                Exit For
            End If
        Next
    Next
    u.Select
End With
End Sub

Works like a dream. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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