Solved

Find Very First Occurence

Posted on 2013-01-21
9
231 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 45

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 45

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 45

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 45

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

13 Experts available now in Live!

Get 1:1 Help Now