Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Serach for certain values in a particular row.

Posted on 2013-11-15
3
Medium Priority
?
321 Views
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...
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
0
Comment
Question by:tesla764
3 Comments
 
LVL 13

Assisted Solution

by:Shanan212
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
0
 
LVL 6

Accepted Solution

by:
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
    Next
End Sub

Open in new window


Hope this works for you.

Joop
0
 

Author Closing Comment

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
In this post, we will learn to set up the Group Naming policy and will see how it is going to impact the Display Name and the Email addresses of the Group.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

571 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