Solved

Find Very First Occurence

Posted on 2013-01-21
9
234 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Rayne
ID: 38802933
hence match or find
0
 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

832 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