Serach for certain values in a particular row.

Posted on 2013-11-15
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Assisted Solution

Shanan212 earned 1000 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 1000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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