Serach for certain values in a particular row.

Posted on 2013-11-15
Last Modified: 2013-11-15
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...
and so on.

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.

Question by:tesla764
LVL 13

Assisted Solution

Shanan212 earned 250 total points
ID: 39651408
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

Accepted Solution

Michael earned 250 total points
ID: 39651411
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
End Sub

Open in new window

Hope this works for you.


Author Closing Comment

ID: 39651502
Yes both of these work very well. Thanks you very much.

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Deploying packaged application using SCCM steps ? 4 37
Everything left of comma in excel 4 44
Need Help with Mapping and Toggling 3 21
MS Excel Formula Help 3 32
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question