Solved

Find Very First Occurence

Posted on 2013-01-21
9
237 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
[X]
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
  • 5
  • 4
9 Comments
 

Author Comment

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

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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:Rayne
ID: 38802933
hence match or find
0
 
LVL 48

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 48

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 48

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

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 …
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

690 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