Serach for certain values in a particular row.

I have a spread sheet that I want to search for certain values in a certain row.

The value "GQ-xxx" will alweays be in row 3.

Examples of GQ-xxx values...
GQ-000
GQ-001
GQ-005
GQ-008
GQ-010_2
and so on.

Process...
Read row 3 Cell by Cell from begining to the end.
Searching for GQ-* (wildcard any value starting with GQ-)

For this example just MsgBox the value to the screen.

Thanks
tesla764Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MichaelConnect With a Mentor Business AnalystCommented:
Hi there,

one approach is like this:

Sub GQ()
    Dim rng As Range, cell As Range
    Dim lc As Integer
    
    lc = Cells(3, Columns.Count).End(xlToLeft).Column
    Set rng = Range(Cells(3, 1), Cells(3, lc))
    
    For Each cell In rng
        If cell.Value Like "GQ-*" Then
            MsgBox cell.Value
        End If
    Next
End Sub

Open in new window


Hope this works for you.

Joop
0
 
Shanan212Connect With a Mentor Commented:
Sub Sample()

    Dim x As Long, lRow As Long
    
    
    lRow = ActiveSheet.Cells(3, Columns.Count).End(xlToLeft).Column
       
    For x = 1 To lRow
        
        If InStr(Cells(3, x).Value, "GQ-") > 0 Then
            MsgBox Cells(3, x).Value
        End If
    Next x
    
End Sub

Open in new window


So this will run through all your columns and pop a message box for each value that has 'GQ-'

If you want to break the loop, press ctrl+break on your keyboard
0
 
tesla764Author Commented:
Yes both of these work very well. Thanks you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.