+ Reply to Thread
Results 1 to 10 of 10

Alternative To FIND to determine Column Number

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Alternative To FIND to determine Column Number

    Hi folks,

    Please Login or Register  to view this content.
    I am using this code to find the column number of the cell containing the value resulting from FIND. It works, but I have discovered it's not accurate. For example, if alias = "Rich", if will find the first instance of "Rich", whether it's "Rich E", or "Rich F" or just "RICH".

    Can anyone suggest an alternative to finding the corresponding column number(cfnd) based on the successful finding of a value (alias) found within a specified row (ref_date_row)

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Alternative To FIND to determine Column Number

    You have to also tell it how to look, where to look and if case sensitive

    Please Login or Register  to view this content.
    Just typed it in withou testing but this would be the idea, the Matchase if omitted will search both upper an lower,
    Hope this helps
    This of course will only find the first instance
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Alternative To FIND to determine Column Number

    Thank you Keebellah! I will take your solution as a good educational opportunity.

    I experimented and found my own solution. Perhaps although effective, may prove problematic later on?

    Please Login or Register  to view this content.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,366

    Re: Alternative To FIND to determine Column Number

    Please Login or Register  to view this content.
    Dim your variable as Variant because it must be able to either hold an Integer or an errorcode.

    After that you can check with IsError which one of the 2 it is and take appropriate action.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Alternative To FIND to determine Column Number

    Hi Bakerman2 ... yes, my solution, dim'ed as a range did result in an error. (Object variable or With block variable not set.)
    After trying to find a solution, I substituted with Hans' code which works also.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,366

    Re: Alternative To FIND to determine Column Number

    Now you have two working solutions.

    Thanks for rep+.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,021

    Re: Alternative To FIND to determine Column Number

    Quote Originally Posted by bakerman2 View Post
    Please Login or Register  to view this content.
    Dim your variable as Variant because it must be able to either hold an Integer or an errorcode.

    After that you can check with IsError which one of the 2 it is and take appropriate action.
    Shouldn't that be:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,366

    Re: Alternative To FIND to determine Column Number

    In this context Yes because Match returns number relative to Range applied.

    Maybe better to use
    Please Login or Register  to view this content.
    to avoid that issue.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,021

    Re: Alternative To FIND to determine Column Number

    I was really commenting on the fact you used rng_cfnd.Column

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,366

    Re: Alternative To FIND to determine Column Number

    Oeps, that was just Copy-Paste without really thinking. (:

+ 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. [SOLVED] Determine last number in a column that contains numbers, and strings
    By anakaine in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-21-2015, 12:21 AM
  2. [SOLVED] determine column number and sum
    By slxia1 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 10-30-2012, 07:56 AM
  3. Replies: 7
    Last Post: 04-19-2011, 04:01 PM
  4. Vlookup column number alternative
    By Blake 7 in forum Excel General
    Replies: 3
    Last Post: 01-24-2011, 05:34 PM
  5. How do I determine Table Column Index Number?
    By sauerj in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 09-17-2010, 09:25 AM
  6. Determine Row Number of Last Value in column
    By lake54 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-15-2009, 02:48 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