Find Last Instance of "Text" in a column

C

Chris Premo

I have a sorted column of text that I want to find the last instance
where the text begins with an asterisk ("*"). I can use this code to
do the search, but I would have to know how many times to "continue the
search". Also, the "~*" will also find any word with the asterisk in
it, while I only want those words with the asterisk as the first
character.


Columns("C:C").Select
Selection.Find(What:="~*", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Selection.FindNext(After:=ActiveCell).Activate




--
 
R

Ron Rosenfeld

I have a sorted column of text that I want to find the last instance
where the text begins with an asterisk ("*"). I can use this code to
do the search, but I would have to know how many times to "continue the
search". Also, the "~*" will also find any word with the asterisk in
it, while I only want those words with the asterisk as the first
character.


Columns("C:C").Select
Selection.Find(What:="~*", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Selection.FindNext(After:=ActiveCell).Activate


If by "last instance" you mean the instance in the highest numbered row in
Column C, and if you mean that the first character in the cell should be an
asterisk, then try this:

==========================
Sub LastAsterisk()
Dim r As Range
Set r = Columns(3).Find(what:="~**", _
after:=Range("C1"), _
lookat:=xlWhole, _
searchdirection:=xlPrevious)

Debug.Print r.Address
End Sub
====================

--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top