+ Reply to Thread
Results 1 to 7 of 7

Find function and column widths

  1. #1
    Registered User
    Join Date
    05-31-2020
    Location
    Norfolk, England
    MS-Off Ver
    365
    Posts
    22

    Find function and column widths

    I've been trying to get my VBA script to find a specific value in a column and return the corresponding row number. The code for this is reasonably straight forward but it has taken me most of yesterday to get it to work. The code is as follows:

    Please Login or Register  to view this content.
    After much head scratching, and by pure luck, I discovered that it wasn't working because the column containing the value that I was searching for was too narrow. The column contains the value I'm looking for and, if I select the cell manually, I can see the value in the Formula bar but for some bizarre reason, Excel can't find it. If I widen the column, hey presto, it finds it! I've since replicated this using the built-in Find function on the toolbar and it behaves exactly the same. Surely the Excel Find function doesn't work visually?!?!

    Has anyone else experienced this and, if so, have any suggestions other than widening the column? I was actually intending to use the code to look up data in a hidden column, but looks like that's out of the question too.
    Last edited by Apollo1969; 08-24-2020 at 02:53 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Fine function and column widths

    Perhaps posting your sheet might help ? ( see yellow banner)

  3. #3
    Registered User
    Join Date
    05-31-2020
    Location
    Norfolk, England
    MS-Off Ver
    365
    Posts
    22

    Re: Find function and column widths

    I can't post the original file as it's full of personal data, but have mocked up the attached by way of example. A simple piece of code searches the SUN column for the value 1269. First button searches column A which is fully visible. Second button uses identical code to search a duplicate column C which has been narrowed.
    Attached Files Attached Files

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: Find function and column widths

    Please Login or Register  to view this content.
    Alternative
    Please Login or Register  to view this content.
    Last edited by sintek; 08-24-2020 at 03:51 AM. Reason: Amended code...
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Registered User
    Join Date
    05-31-2020
    Location
    Norfolk, England
    MS-Off Ver
    365
    Posts
    22

    Re: Find function and column widths

    Thanks sintek,

    That code produces the exact same error... the issue is that if the column width is reduced such that the values appear as ####, Excel can't find the data, even though it is still there in the cells.

  6. #6
    Registered User
    Join Date
    05-31-2020
    Location
    Norfolk, England
    MS-Off Ver
    365
    Posts
    22

    Re: Find function and column widths

    Oops, didn't spot your alternative code until I'd posted. The second option does work, but would love to know why Excel can't find it using Find (even using the toolbar Find button doesn't work on a narrow column)

    Thanks for your help

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,192

    Re: Find function and column widths

    Find only looks for displayed values...

    Option 1 works for find - narrow column...lookin:=xlformulas

    Or just autofit column widths prior to search...

+ 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: 11-05-2015, 11:58 AM
  2. [SOLVED] Help with modifying VBA Macro - Works fine but needs fine tuning !
    By stefan27 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-06-2015, 10:27 AM
  3. Column chart with varying column widths and picture fill help
    By ldewson86 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 10-12-2013, 05:39 AM
  4. [SOLVED] User Form ListBox Column Widths - How to set widths for unknown number of columns
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-10-2013, 05:24 AM
  5. Need copy the column d instead of column b, macro working fine for column b
    By audax48 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-20-2012, 04:32 PM
  6. [SOLVED] Column widths
    By Zack Barresse in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 09-06-2005, 07:05 PM
  7. Column widths
    By Zack Barresse in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 AM

Tags for this Thread

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