+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Using a column in If Else statement

    How am i be able to do this. If im going to use Mod on B3 and there is a statement saying,
    if z = 0 then, it will use the D3; if z = 1 it will use E3; if z = 2 it will use F3 and so on. z is equals to the Mod equivalent on B3.
    The Mod will be only 8. I' am just new in Excel VBA..
    Attached Files Attached Files

  2. #2
    Forum Guru zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2007
    Posts
    5,740

    Re: Using a column in If Else statement

    What is z?
    "Relax. What is mind? No matter. What is matter? Never mind!"

  3. #3
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using a column in If Else statement

    z is the equivalent of the number that is being Mod. Mod(B3,8) = z

  4. #4
    Forum Guru zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2007
    Posts
    5,740

    Re: Using a column in If Else statement

    Is this what you looking for (in B3):

    =INDEX($D3:$K3,1,MOD(CODE(A3),8))

    However, MOD(84,8) is 4... so why is 205 in red instead of 147?
    "Relax. What is mind? No matter. What is matter? Never mind!"

  5. #5
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using a column in If Else statement

    Well it is just an example.. If z = 0 it will use D3 as a value.. does this INDEX command work on If Else statements? and how to construct that in a VBA Module?
    Last edited by Izeath; 03-09-2010 at 09:39 PM.

  6. #6
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Using a column in If Else statement

    @zbor: given MOD 0 is D should your formula not in fact be:

    =INDEX($D3:$K3,1+MOD($B3,8))
    (ie result for row 3 would in fact be 89 rather than 147)

    @Izeath - what is your utlimate goal - ie what are you using the above calculation for exactly ?

  7. #7
    Forum Guru zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2007
    Posts
    5,740

    Re: Using a column in If Else statement

    True, true
    "Relax. What is mind? No matter. What is matter? Never mind!"

  8. #8
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using a column in If Else statement

    I was just wondering if how to make the INDEX command in a VBA Module. But the command you guys posted here is just what i need.

    Thanks zbor and DonkeyOte

  9. #9
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using a column in If Else statement

    Another question, is there a certain function that instead of getting 89 in the =INDEX($D3:$K3,1+MOD($B3,8)), it will look for another value below 89? Like if z = 1 it will choose the value 221? it will go down 1 cell? or if z = 2 it will go down 2 cells?

  10. #10
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Using a column in If Else statement

    Change the INDEX range and then perhaps (if I've understood)

    =INDEX($D3:$K$2108,1+MOD($B3,8),1+MOD($B3,8))

    you could also use OFFSET, however, OFFSET is a Volatile function - may / may not be a concern to you

  11. #11
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using a column in If Else statement

    =INDEX($D3:$K$2108,1+MOD($B3,8),1+MOD($B3,8)) I tried to use 255 instead of 8 but it turns out to be #REF! How can i fix it?

  12. #12
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Using a column in If Else statement

    The range D:K has only 8 columns - a column index_num outside of that range (1-8) will result in a #REF error.

  13. #13
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using a column in If Else statement

    i got 8 columns. when i choose a column it doesn't end there but it would choose a row below it. so after picking a value at $D3:$K3, e.g. it chose $J3, then it would choose a value from 0-255 ranging from $J3:$J252. i hope you understand.

  14. #14
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Using a column in If Else statement

    INDEX with a matrix range works along the lines of:

    =INDEX(range,row,column)

    not

    =INDEX(range,column,row)

  15. #15
    Registered User
    Join Date
    03-09-2010
    Location
    Manila, Philippines
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Using a column in If Else statement

    Quote Originally Posted by DonkeyOte View Post
    INDEX with a matrix range works along the lines of:

    =INDEX(range,row,column)

    not

    =INDEX(range,column,row)
    i see. so is there any way in excel we could do what i just said? any help would be highly appreciated.

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.2.0