+ Reply to Thread
Results 1 to 5 of 5

Search function in VBA with conditions

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Search function in VBA with conditions

    I am using a input box and a find function to find the first number in Column A which starts with the 3 digit number that the user types into the input box. This, however, creates errors by the 100th row or so, when that 3 digit number appears in other data previously in the sheet. So I need a SEARCH function that will search for the 3 digit number typed in by the user, and only look in the first 3 digits of column A to find this. I hope this makes sense, and I hope that someone can help?

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Search function in VBA with conditions

    Ruandi,

    Welcome to the forum!
    Give this a try:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    04-11-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Search function in VBA with conditions

    Thanx it works perfectly for the biggest part, except that I have some cases where the machine number starts with a zero. So I will type in 012 and then it will return "No matches for [12]". How do I adjust this code so that it doesn't eliminate the zero at the start of the 3 digits? I've tried changing define dFind as a string, but it just gives the same problem. I've also tried putting dFind in inverted commas in the find functions, but it also doesn't work. Any solutions?

  4. #4
    Registered User
    Join Date
    04-11-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Search function in VBA with conditions

    I got the problem of the zero solved by playing around with the code. I my solution, with comments to explain the changes, was:

    Please Login or Register  to view this content.
    Thank you very much for the help! I'm so glad I registered on this Forum!
    Last edited by davesexcel; 04-19-2013 at 08:42 PM. Reason: Code tags required when supplying VBA code, please read the forum rules.

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Search function in VBA with conditions

    You're very welcome, and I'm glad you got it sorted

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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