+ Reply to Thread
Results 1 to 6 of 6

Problems searching Excel cells for InStr text comparison, cant get cell values ...

  1. #1
    Registered User
    Join Date
    02-08-2004
    Posts
    58

    Problems searching Excel cells for InStr text comparison, cant get cell values ...

    I am trying to compare text/ InStr textcompare in Excel cells (z1, to z24) in sheet1, 2, 3. This will be compared to say, textbox1.

    I want to search the z1,z24 cells for the textbox1 contents.






    Here was what I came up with but it doesn't work:
    'this is what I came up with, but the 'cellblock' variable is being set to the "text" not the actual cell contents...
    'this sets the cellblock variable to "sheet1.range(z1).value" -- where as, it should actually be the "contents" of the cell, not the name of it....
    Please Login or Register  to view this content.






    My crude programming is not allowing it to work correctly. Is there a better way to do this ??


    Thanks !
    Last edited by BaLLZaCH; 05-25-2008 at 10:13 AM.
    Sig ? How can I sign the computer screen ?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Change the cellblock variable to:
    Please Login or Register  to view this content.
    One other point. I note that you're using 'loop:' and 'ending:' as goto labels. There's nothing inherently wrong with that and it will work, but IMO it's not always good practice since it's all too easy to develop 'spaghetti' code. This can make subsequent debugging much harder.

    I'd advise using 'proper' loop structures like For..Next (where the number of interations is known in advance, or Do..Loop, Do While..Loop, Do..Loop Until etc, where the exit from the loop is dependent on something that changes within the loop.

    HTH

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, You could try this:-
    Please Login or Register  to view this content.
    Regards Mick

  4. #4
    Registered User
    Join Date
    02-08-2004
    Posts
    58
    Hey Richard, that seemed to be the easiest fix but I couldn't get it to work... All it produced was NULL values for me. I do agree with you about the loop and ending, it was a quick example I usually use "loop1" or something, and I use loop1(s) and ending1(s) because I am not great with VB code, I have to take the crude approach...


    MickG, I used your example and changed it to "InStr" instead of "=", and modified it to work with the entire book. I had to rework the way "true/false" was handled, but,


    IT WORKS GREAT !!!
    (Uhh ohh, I just realized the code is case sensitve... Isnt there a $case or something like that I could use to make it non-case-sensitive, or binary mode or something? I will start my own research but a quick reference would be helpful)
    [NEVERMIND, resolved, I did it another way by just converting everything to UPPER case.... problem solved]


    Thank you both for your input.



    [RESOLVED]
    Last edited by BaLLZaCH; 05-26-2008 at 10:59 AM.

  5. #5
    Forum Contributor
    Join Date
    03-25-2008
    MS-Off Ver
    Excel, Outlook, Word 2007/2003
    Posts
    245
    Please Login or Register  to view this content.
    on top of your module. Before any sub or function will do the trick. So A=a ...

    Charlize

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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