+ Reply to Thread
Results 1 to 5 of 5

Using Find to search from back to front in a range

Hybrid View

TechKnowledge Using Find to search from... 06-26-2016, 03:11 PM
Leith Ross Re: Using Find to search from... 06-26-2016, 03:47 PM
TechKnowledge Re: Using Find to search from... 06-26-2016, 03:59 PM
Leith Ross Re: Using Find to search from... 06-26-2016, 04:26 PM
jolivanes Re: Using Find to search from... 06-26-2016, 07:03 PM
  1. #1
    Registered User
    Join Date
    07-12-2014
    Location
    Rome, Georgia
    MS-Off Ver
    2011 Mac
    Posts
    52

    Using Find to search from back to front in a range

    I have this simple macro:

    Sub LastColRng()
    Dim SelRange As Range
    Set SelRange = Selection
    Dim LastCol As Long
    
            SelRange.Resize(, 261).Select
              LastCol = SelRange.Find("*", after:=SelRange(1, 1), SearchDirection:=xlPrevious).Column
                 MsgBox LastCol
    
    End Sub
    I expect it to return the column number of the rightmost cell with text in the range, but instead it returns the column number of the first cell in the range. What am I doing wrong?
    Last edited by TechKnowledge; 06-26-2016 at 03:15 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Using Find to search from back to front in a range

    Hello TechKnowledge,

    This works...
    Sub LastColRng()
    
        Dim SelRange    As Range
        Dim LastCol     As Long
    
            Set SelRange = Selection.Resize(ColumnSize:=261)
            LastCol = SelRange.Find("*", SelRange.Cells(1, 1), xlValues, xlPart, xlByRows, xlPrevious, False, False, False).Column
            MsgBox LastCol
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-12-2014
    Location
    Rome, Georgia
    MS-Off Ver
    2011 Mac
    Posts
    52

    Re: Using Find to search from back to front in a range

    Thank you!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Using Find to search from back to front in a range

    Hello TechKnowledge,

    You're welcome.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Using Find to search from back to front in a range

    Would this not give the same result? I know you mentioned "Find" so if that is a must, forget about this.
    The only thing I do not know if it works on a Mac.
    Sub Why_Not_This()
    MsgBox Cells(Selection.Row, Columns.Count).End(xlToLeft).Column
    End Sub

+ 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: 2
    Last Post: 06-20-2015, 06:11 AM
  2. Search or Find to False in a row/back to back
    By zit1343 in forum Excel General
    Replies: 2
    Last Post: 04-20-2012, 04:35 PM
  3. How Would I Add * Mark to Front and Back of All Cells?
    By JannaMay17 in forum Excel General
    Replies: 4
    Last Post: 03-31-2012, 03:46 AM
  4. Access Front-end, Excel Back-end
    By dreicer_Jarr in forum Excel General
    Replies: 3
    Last Post: 03-08-2010, 08:07 PM
  5. How can we link front-end to back-end using UNC
    By joe41 in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2009, 11:23 AM
  6. Print Sheets front to back
    By maui1girl in forum Excel General
    Replies: 2
    Last Post: 12-02-2007, 07:20 PM
  7. I can not get excel to print on front and back can anyone help me.
    By de_stap in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-01-2006, 02:40 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