+ Reply to Thread
Results 1 to 7 of 7

Search Range for cell that begins with "Pri"

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-27-2012
    Location
    Somerset, Kentucky
    MS-Off Ver
    Excel 2007
    Posts
    123

    Search Range for cell that begins with "Pri"

    The ActiveCell is A100. I need VBA or a formula, that will start with Cell A99 and keeps looking in each next cell above until it arrives at the first cell directly above A100 thats content begins with the letters "Pri". Take into account, there could be no cell that begins with "Pri", so help me avoid an "error".

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search Range for cell that begins with "Pri"

    Try this:

    Sub Scabtree(): Dim r As Long
             r = 99:    Do
        If LCase(Left(Cells(r, 1), 3)) = "pri" Then _
            Cells(r, 1).Select: Exit Sub
                r = r - 1: Loop Until r = 0
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    07-27-2012
    Location
    Somerset, Kentucky
    MS-Off Ver
    Excel 2007
    Posts
    123
    Thanks. I just gave A100 as an example. The active cell could be any cell in column A. Sorry for the trouble/lack of clarity.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this ‼


    As a starter :

    PHP Code: 
    Sub Demo1()
               
    Dim Rg As Range
        
    If ActiveCell.Column 1 Then
               Set Rg 
    Range("A1"ActiveCell).Find("Pri*"ActiveCellxlValuesxlWhole, , xlPrevious)
            If 
    Not Rg Is Nothing Then Rg.SelectSet Rg Nothing
        End 
    If
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: Search Range for cell that begins with "Pri"

    Option Explicit
    Sub Scabtree()
        Dim SelCel      As Range, _
            PRILOC      As Variant, _
            SearchRng   As Range
        
        'Option 1
        Set SelCel = ActiveCell
        
        'Option 2
        'Set SelCel = Cells(Rows.Count, "A").End(xlUp)
             
        Set SearchRng = Range("A1", SelCel)
        
        With SearchRng
            Set PRILOC = .Find("pri*", _
                after:=SelCel, _
                LookIn:=xlValues, _
                SearchDirection:=xlPrevious, _
                MatchCase:=False)
        End With 'searchrng
            
        If Not PRILOC Is Nothing Then
            MsgBox "-pri- found at: " & PRILOC.Address
        Else
            MsgBox "-pri- not found"
        End If
    End Sub
    Last edited by protonLeah; 05-10-2018 at 09:43 PM.
    Ben Van Johnson

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Search Range for cell that begins with "Pri"


    Thanks for the rep' !

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search Range for cell that begins with "Pri"

    Thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 03-21-2014, 09:58 AM
  2. advanced filter criteria "begins with" and "does not begin with"
    By Eddie O in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-06-2005, 12:05 PM
  3. advanced filter criteria "begins with" and "does not begin with"
    By Eddie O in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-06-2005, 04:05 AM
  4. advanced filter criteria "begins with" and "does not begin with"
    By raph_baril in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  5. Backup to specific folder if workbook names begins with "NSR" or "MAC"
    By GregR in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-05-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1