CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2010
    Posts
    2

    VB 6 If Statement question

    =IF(LEFT(RC[2],1)=""0"",IF(mid(RC[2],10,2)=""-c"",LEFT(RC[2],11),LEFT(RC[2],9)),if(right(rc[2],2)=""-c"",RIGHT(RC[2],11),RIGHT(RC[2],9)))"

    With the code above:
    =IF(LEFT(RC[2],1)=""0"", - looks for zero(0) as the first character in the cell. I want to search for one(1) also.

    If I change the "0" to "1" I get all that begin with 1. I need to find both "0" and "1"

    Data I'm looking for:
    09-B-6399
    10-B-0568

    Hopefully you can help, need this for work, creator has moved onto another company.

    Dave

  2. #2
    Join Date
    Oct 2006
    Posts
    327

    Re: VB 6 If Statement question

    Hello, dintym

    Wrong section ...

    It's anything (VBA/Excel, I guess) but VB6 !

    Sorry : it's not even VBA, but an Excel Formula in an Excel cell...

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB 6 If Statement question

    >8 and <11

    should work
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Oct 2006
    Posts
    327

    Re: VB 6 If Statement question

    It's not VB (as said) but an Excel Formula.
    The logic of the syntax is then quite different from VB and should respond to this mecanism :

    = IF(OR(expression1,expression2)......)

    where :
    expression1 has to express that the first character is a "0"
    expression2 has to express thant the firts character is a "1"

    An example (but on my French Excel Version, so that it has to be transformed...)
    Code:
    = SI(OU(GAUCHE(B2;1) = "0";GAUCHE(B2;1) ="1");VRAI;FAUX)
    this, placed in the cell C4 (for instance) would display (in C4) a boolean showing whether the first character in B2 is or not a "0" or a "1" .

    The transposition for an english version should be (I think) something like this :
    Code:
    = IF(OR(LEFT(B2,1) = "0",LEFT(B2,1) ="1"),TRUE,FALSE)
    Just observe : the transposition is not only a translation of the words. Notice than every : (in french formula) is now a , (in english formula). Well (from what I guess....)

    Well... This is exactly why the present discussion should not be opened in VB6 section.

    EDIT : a big mistake would be to use a single comparison with < "2", as (for instance) "^blabla" would display TRUE !

    EDIT 2

    One could also use the AND function, like this :
    Code:
    = IF(AND(LEFT(B2,1) >= "0",LEFT(B2,1) <"2"),TRUE,FALSE)
    Last edited by moa; January 14th, 2010 at 04:00 AM.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB 6 If Statement question

    or like this (from ENGLISH version of Excel 2007)

    B3 is text

    Code:
    =IF(OR(LEFT(B3,2)="00",LEFT(B3,2)="01"),TRUE,FALSE)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Oct 2006
    Posts
    327

    Re: VB 6 If Statement question

    Let us now hope that dintym, who seems to be a beginner, will understand that the project he is working on is using the R1C1 notation, so that the absolute address (ie B2 or B3 in our examples) has to be replaced by RC[2] in his project.
    We never know

  7. #7
    Join Date
    Jan 2010
    Posts
    2

    Re: VB 6 If Statement question

    I stand corrected and humbled. Thanks for being kind to one who is better at repairing cars and raising chickens than programming.

    Dave Dinty Moore

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured