+ Reply to Thread
Results 1 to 12 of 12

convert the if conditions to OR conditions

  1. #1
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    convert the if conditions to OR conditions

    Hello everybody,

    I have the following if conditions which I have to convert into OR statements in a simple way. That is, if either one of this condition is true then the variable count should be updated (count =count +1)
    Please Login or Register  to view this content.
    Thank you
    Vijay
    Last edited by nynamyna; 03-10-2011 at 11:22 AM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: convert the if conditions to OR conditions

    Hi Vijay
    Try this:
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: convert the if conditions to OR conditions

    @MarvinP, I've not looked at the question but noticed a couple of possible corrections / modifications ?

    Please Login or Register  to view this content.
    in the above Rows.Count should also be qualified (per Cells)

    Please Login or Register  to view this content.
    would probably be better written as

    Please Login or Register  to view this content.
    this way if the Column Array is modified the subsequent iteration will adapt accordingly (given the Split you could persist with 0 if preferred)

  4. #4
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: convert the if conditions to OR conditions

    I am getting a type mismatch error here

    Please Login or Register  to view this content.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: convert the if conditions to OR conditions

    DO,

    So you're saying I needed
    With WkSht
    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    Where I needed a period before the Rows.Count? This has plagued me for the last few months.

    Also - In the need for Split( ) to get values into an array. Isn't there an easier way? Can't I somehow just declare an Array with values of numbers? Like MyArray = {2,3,4,5} ?

  6. #6
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: convert the if conditions to OR conditions

    Please Login or Register  to view this content.
    Shouldn't this be not equal to

    Please Login or Register  to view this content.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: convert the if conditions to OR conditions

    My mistake! Also beware of the period in front of Rows.Count in the LastRow = statement.

    I guess part of my signature line of "One Test is worth a Thousand Opinions" means testing is needed to insure thing work correctly.

    Sorry. I hope you can use my close-code and get it to work for you.

  8. #8
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: convert the if conditions to OR conditions

    What should I do for that type mismatch error ?

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: convert the if conditions to OR conditions

    Quote Originally Posted by nynamyna
    What should I do for that type mismatch error ?
    Quote Originally Posted by MarvinP
    Also - In the need for Split( ) to get values into an array. Isn't there an easier way? Can't I somehow just declare an Array with values of numbers? Like MyArray = {2,3,4,5} ?
    To kill 2 birds with one stone:

    Please Login or Register  to view this content.
    In the most general of terms to assign multiple values to an array simultaneously requires the Array be of Variant type (as opposed to Long for ex.)

    Again - I've not actually looked at the code in relation to the question itself.

  10. #10
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: convert the if conditions to OR conditions

    I am getting

    Application-defined or object-defined error here

    Please Login or Register  to view this content.
    this is the code i am using

    Please Login or Register  to view this content.

  11. #11
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: convert the if conditions to OR conditions

    Here is the revised code.
    I need to learn and then OWN the Stuff = Array( Other Stuff).. Thanks DO.
    Please Login or Register  to view this content.
    I have no idea what you are counting in this code but the above example should give you some ideas. Funny stuff is that Arrays first member is the zero guy. So in above ColArray(0) = 2. The 2 is the column of "B".
    I've also corrected the above with the period before Rows in the LastRow line.

    hope this gets you what you want from your first try at code above.

  12. #12
    Registered User
    Join Date
    08-19-2009
    Location
    united states
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: convert the if conditions to OR conditions

    I am getting

    Application-defined or object-defined error here


    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