Solved

Find Very First Occurence

Posted on 2013-01-21
9
232 Views
Last Modified: 2013-01-21
Hello All,

I have a find issue.
I am looking at a entire column in excel. I want to do this:
Using find or match, whatever fast - find the very first occurrence of a string. For example: if my string I am looking for, is banana and "banana" repeats multiple times in this target column, then that find returns me only the VERY first banana string in that column

Is that possible?

Thanks

R
0
Comment
Question by:Rayne
  • 5
  • 4
9 Comments
 

Author Comment

by:Rayne
ID: 38802776
I need VBA for this
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38802844
Dim lngLastRow as Long
Dim lngIndex As Long
' This assumes the data is in column 'A'
lngLastRow = Range("A65536").End(xlUp).Row

For lngIndex = 1 To lngLastRow
    ' '1' is column A
    If Cells(lngIndex, 1).Value = "banana" Then
        MsgBox "First one is in row " & lngIndex
        Exit Sub
    End If
End If
0
 

Author Comment

by:Rayne
ID: 38802931
Hello Martin,

I don't prefer this method as I would be looping several times over 50000 rows and doing this, will slow this down as I have to do this for several files, one at a time :(
0
 

Author Comment

by:Rayne
ID: 38802933
hence match or find
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 38802961
Cells.Find(What:="banana", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
0
 

Author Comment

by:Rayne
ID: 38802993
Martin

Thank you :)

Some verification:
SearchOrder:=xlByColumns, - or will it be xlByRows? Whats the difference between the two?

 After:=ActiveCell - if the activecell changes, would that effect the sequence of search like A1 or C5?

Thanks
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 38803017
I assume the difference is that ByRows would do a left to right, top to bottom search whereas ByCol would do top to bottom, right to left. As for After…, I'm not sure but you could easily test that in simple sheet with just a few items.
0
 

Author Closing Comment

by:Rayne
ID: 38803063
Thank you Martin :)
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38803076
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now