+ Reply to Thread
Results 1 to 108 of 108

Cell value dependent on multiple conditions

  1. #1
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Post Cell value dependent on multiple conditions

    My range1 is D4:M4 & range2 is D6:M6. Both range1 & range2 consists numerical values
    Range3:D10:M10 which consists of “1” or “0”

    Output cell: Q6 which should give result as per the below conditions:
    1. Formula should check the ‘last’ cell in which “1” appears in D10:M10
    2. Now it has to consider range1 & range2 both up to the column in which ‘last’ “1” appears.
    3. Then starting from the 1st column of range1 and range2, Q6=D6,IF(D4>E4 AND D6>E6)
    4. Else Q6=D6,IF(D4>F4 AND D6>F6),E6,IF(E4>F4 AND E6>F6)
    5. Else Q6=D6,IF(D4>G4 AND D6>G6),E6,IF(E4>G4 AND E6>G6),F6,IF(F4>G4 AND F6>G6)
    And so on…….

    Q6=0, IF all D10:M10=0 OR all cells of range1=0 OR all cells of range2=0

    How to accomplish?
    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Cell value dependent on multiple conditions

    Maybe try

    =IFERROR(LOOKUP(2,1/(D4:M4>D6:M6)/D10:M10,D6:M6),)
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Some modification in the formula may be required.
    To check its working, I changed 1 value i.e. H10=0 (from H10=1), but the formula gives G6 i.e. 320 (wrong).
    The last “1” appears in G10 so the range to be considered is D4:G6…although G4<F4 & also G4<E4 but G6 is not less than F6 (corresponding cell) & G6 is not less than E6 (corresponding cell) respectively for the formula to give G6 as answer.
    Here since this condition does not fulfills, so the answer would be “” (null).

    Modification in the formula is requested.

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,567

    Re: Cell value dependent on multiple conditions

    If I understand correctly then the following seems to work:
    Populate T4:AC4 using: =IFERROR(INDEX($D4:$M4,AGGREGATE(14,6,(COLUMN($D4:$M4)-COLUMN($C4))/($D10:$M10>0),COLUMNS($T6:T6))),"")
    Populate T6:AC6 using: =IFERROR(INDEX($D6:$M6,AGGREGATE(14,6,(COLUMN($D6:$M6)-COLUMN($C6))/($D10:$M10>0),COLUMNS($T6:T6))),"")
    Populate cell Q6 using: =IF(AND(MAX(U6:AC6)>T6,MAX(U4:AC4)>T4),T6,"null")
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  5. #5
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    JeteMc
    This is second instance which clearly proofs that you are ‘master in visualizing an excel scenario”
    Your formula is picking a ‘different cell’ value as an answer than the ‘required cell’ which should have been considered for answer.
    Please see the attached file.
    Formula is giving L6 as answer but it should be giving I6 as answer.

    Reason:
    Last “1” appears in L10; therefore D2:L6 is the range to be considered.
    L4<I4 AND L6<I6
    So all my conditions are met….the answer required is I6 & not L6
    Attached Files Attached Files
    Last edited by bittubadri; 07-10-2022 at 01:19 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Cell value dependent on multiple conditions

    Try this tweak:

    =IF(AND(MAX(U6:AC6)>=T6,MAX(U4:AC4)>T4),T6,"null")
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    No, Q6 still gets L6 (wrong); it should get I6 in this scenario

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Cell value dependent on multiple conditions

    Explain why I6 should be the answer.

  9. #9
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Last “1” appears in L10. So only up to D2:L6 has to be considered & not complete D2:M6
    Now L6 has to be checked in such a way:
    1. ‘Last’ value from D6:K6 (before L6) has to be picked for satisfying >L6; plus
    2. If I6 is the cell (satisfying condition #1), then it should also satisfy I4>L4
    3. If condition #2 is completely met, then Q6=I6 else ‘’ (null)

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Cell value dependent on multiple conditions

    I still don't understand.

    This formula does EXACTLY what you have just described, I think, and returns 274:

    =IF(AND(LOOKUP(2,1/(D10:M10=1),C6:L6)>LOOKUP(2,1/(D10:M10=1),D6:M6),LOOKUP(2,1/(D10:M10=1),D4:M4)>LOOKUP(2,1/(D10:M10=1),D6:M6)),LOOKUP(2,1/(D10:M10=1),D6:M6),"")

    Please explain HOW you have arrived at 275. More detail, please.

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Try

    in Q6

    =IFERROR(INDEX($D$6:$M$6,AGGREGATE(15,6,(COLUMN($D$1:$M$1)-COLUMN($D$1)+1)/($D$4:$M$4>=$T$4)/($D$6:$M$6>=$T$6),1)),"Null")
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  12. #12
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Updated..

    =IFERROR(INDEX($D$6:$M$6,AGGREGATE(15,6,(COLUMN($D$1:$M$1)-COLUMN($D$1)+1)/($D$10:$M$10=1)/($D$4:$M$4>=$T$4)/($D$6:$M$6>=$T$6),1)),"Null")

  13. #13
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John, Your formula is very 'near' to the solution. Please see the attached file.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Your formula gives Q6=L6 (274)
    It should give Q6=G6 (300)
    1. In D6:K6, the nearest value >L6 is K6 (but K4<=L4), so K6 cannot be the answer.
    2. In D6:J6, the nearest value >L6 is J6 (but J4<=L4), so J6 cannot be the answer.
    3. In D6:I6, the nearest value >L6 is I6 (but I4<=L4), so I6 cannot be the answer.
    4. In D6:H6, the nearest value >L6 is H6 (but H4<=L4), so H6 cannot be the answer.
    5. In D6:G6, the nearest value >L6 is G6 (Here G4>L4), so G6 is the answer.
    Attached Files Attached Files

  15. #15
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    I am out !!!

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Cell value dependent on multiple conditions

    The problem here is that you have failed to explain properly what you want. You have given only ONE working example to illustrate what you want, which you should know by now is not enough. You are drip-feeding clues and expecting us to somehow know exactly what the criteria are.

    I am out as well. Sorry!

  17. #17
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    If I mark this thread is solved, then can I post this message on any other Excel help website? Then will you treat it as cross posting?

  18. #18
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Cell value dependent on multiple conditions

    You have been a member long enough to know the answer to this!!!

    You MAY cross post, however you MUST share the link or links here. You MUST do the same on the other website(s). You do NOT need to mark this as solved, and in any case, it isn't.

    You may NOT post the same question in a new thread HERE - that would be a duplicate thread and would be closed.

    One of our wizards who's not yet online may be able to help you later on.

    Perhaps you need to have a read of the forum rules to refresh your memory?
    Last edited by AliGW; 07-10-2022 at 06:19 AM.

  19. #19
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Try


    Please Login or Register  to view this content.
    =findIt($D$4:$M$4,$D$6:$M$6,$T$4)

    in T10 of attached
    Attached Files Attached Files

  20. #20
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    No Sir, this vba code does not give correct answer. But once again, I would like to say that you have understood the scenario/(s) & may be missing 1 or 2 & because of these missing’s scenario/(s), incorrect answers are coming.
    It is presupposed, If last “1” appears in K10 in D10:M10; corresponding K6 cannot be the answer.
    Similarly, If last “1” appears in J10 in D10:M10; J6 cannot be the answer.

    I tested your code by making K10=1. It gives J6 as answer (wrong).
    For J6 to be the answer; ALL below 3 conditions should have been met:
    1. Either of K10 OR L10 OR M10=1
    2. J6>K6
    3. J4>K4

    In the workbook attached with your code kept as it is; K10=1
    Now out of 3 conditions as above:
    1. Either of K10 OR L10 OR M10=1 YES K10=1 Condition met
    2. J6>K6 NO (here J6<K6) Condition NOT MET
    3. J4>K4 YES (here J4>K4) Condition met

    2nd condition was NOT MET, so J6 cannot be the answer.

    H6 is the answer (let us see why?)
    1. Either of I10 OR J10 OR K10 OR L10 OR M10=1 YES K10=1 Condition met
    2. H6>K6 YES (here H6>K6) Condition met
    3. H4>K4 YES (here H4>K4) Condition met
    Attached Files Attached Files
    Last edited by bittubadri; 07-10-2022 at 07:30 AM.

  21. #21
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    I give up trying to understand the logic as it is not clear whether T6 or T4 is the key parameter: your solution suggests the value "closest" to T4 in D$:M4.
    Last edited by JohnTopley; 07-10-2022 at 07:42 AM.

  22. #22
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Sir,
    I will make it simplest.
    1. Answer has to be either of D6:L6
    2. For answer=J6, then AND(OR(K10=1,L10=1,M10=1),J6>K6,J4>K4)

    I don’t understand T6 or T4, they have been added by you (must have been for some good reasons)

  23. #23
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Please Login or Register  to view this content.
    =findIt($D$4:$M$4,$D$6:$M$6,$T$4,$T$6)

  24. #24
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    I changed the formula of T10 as =findIt($D$4:$M$4,$D$6:$M$6,$T$4,$T$6)
    pasted the new code, but T10 is always giving #VALUE!

  25. #25
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    See attached
    Attached Files Attached Files

  26. #26
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    It works 99%. When I made K6=297, T10 is giving 297 whereas it should give H6 (343).
    I think may be K6 (297) found another 297 (J6), thats all

  27. #27
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    What do you expect if you have duplicate values ?.. it will find the first pair that matches the criteria. So logically, it is correct.

    Change to

    If a(i) > c And b(i) > d Then

    i.e remove the "=" condition
    Last edited by JohnTopley; 07-10-2022 at 08:42 AM.

  28. #28
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Thanks a lot John for your extreme support. This is 'what is required by me'. May you have a blessed day & everyday.

  29. #29
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    John I was trying to understand your code.
    The 1st line in the code starts with
    Function findIT (......) As String
    but the 2nd last line is
    finIT = "Null"
    I want to ask, 2nd last line should it be
    findIT = "Null" OR it is okay.

  30. #30
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    typo:

    findIT = "Null" is correct

  31. #31
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    John, Please bear with me
    Apart from the Worksheet with tab named as XYZ; there are 2 more Worksheets. Will this code disturb other 2 Worksheets also. If yes, then I need the code to run only in the Worksheet with tab named XYZ
    Is U4:Y6 (helper cells inserted by you) necessary? Can I DELETE it?
    Last edited by bittubadri; 07-10-2022 at 12:17 PM. Reason: Updated

  32. #32
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    The helper cells are from JeteMc But retain formula in column T as this determines where the last "1" data resides in D:M.

    Other workshhets are not affected by this function.

  33. #33
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    so the helper cells can be deleted without effecting code's result?

  34. #34
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,
    I would be using your code in my Workbook with a Worksheet with tab named XYZ from tomorrow. My Workbook gets real time feeds in a worksheet tab named “7” & the values in it are continuously updated up to a certain time period.

    I tried to ‘copy’ your code’s sentences to make it a bigger code so that I can get ‘high’ in T9 & ‘low’ in T10. I could only succeed in getting the ‘high’ in T9 (your code did it, not me) but failed to get ‘low’ in T10. I kept all the columns as it is including T4 & T5 (but deleted U, V, W, X)

    I have attached the Workbook. Please tweak the code so that it can also populate ‘low’ in T10.
    Attached Files Attached Files

  35. #35
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Why did you change the test in "findlow"?

    If a(i) < c And b(i) < d Then

    instead of (correct)

    If a(i) > c And b(i) > d Then

  36. #36
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    removed need for any helper columns

    Please Login or Register  to view this content.
    =findhigh($D$4:$M$4,$D$6:$M$6,$D$10:$M$10)

    =findlow($D$4:$M$4,$D$6:$M$6,$D$10:$M$10)
    Last edited by JohnTopley; 07-11-2022 at 06:13 AM.

  37. #37
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,
    Your revised code with findhigh & findlow works fine.
    1. Can I delete T4 & T6 now?
    2. Just like D4:M6; there are 7 more ‘similar’ ranges in this Worksheet which requires ‘similar’ evaluation to throw the required findhigh & findlow. The 7 ranges are:
    1. D12:M13 (T12=findhigh & T13=findlow)
    2. D15:M16 (T15=findhigh & T16=findlow)
    3. D18:M19 (T18=findhigh & T19=findlow)
    4. D21:M22 (T21=findhigh & T22=findlow)
    5. D24:M25 (T24=findhigh & T25=findlow)
    6. D27:M28 (T27=findhigh & T28=findlow)
    7. D30:M31 (T30=findhigh & T31=findlow)
    3. The ‘controlling’ “1” for all these 7 ranges are the same D10:M10.

    Sir, the revised code is required to get the ‘new’ 7 findhigh & findlow in Column T.
    This would really help me. I was not expecting vb as a solution but now this is my final requirement.
    Attached Files Attached Files

  38. #38
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Just change to ranges in

    =findhigh($D$4:$M$4,$D$6:$M$6,$D$10:$M$10)

  39. #39
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Quote Originally Posted by JohnTopley View Post
    Just change to ranges in

    =findhigh($D$4:$M$4,$D$6:$M$6,$D$10:$M$10)
    This =findhigh($D$4:$M$4,$D$6:$M$6,$D$10:$M$10) is now already there since your thread #36. Some typo missings?

  40. #40
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    no: I am telling you what needs changing when the formula is put in T12/T13 etc.

  41. #41
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Okay got it.
    Today I tested the code in practical situation.
    Code gives a value in findhigh & findlow; against a corresponding last “1” found in D10:M10; even if the corresponding cell in row#x & row#y contains either of “0” (zero) or “” (null). In such a case, findhigh & findlow should be 0 (zero).
    Slight revision in the code is requested Sir.
    Attached Files Attached Files

  42. #42
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Please Login or Register  to view this content.

  43. #43
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John, now the code works perfectly well. I added
    If b(n) = 0 Or b(n) = "" Then GoTo finish

    2 times; for the code to take care of cell value being=“0” OR “” for all cells of the 2nd rows.

    Many thanks for your time & efforts spent for me.

  44. #44
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Please mark as SOLVED: "Thread Tools" at top of page.

  45. #45
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    The Excel Workbook is very heavily 'hanged'. In a different worksheet its some of the cells gets real time feeds. Even in the code where to add Application.Screenupdating=TRUE & Application.EnableEvents=TRUE. Any more such commands needed to be added in the code because the Excel Workbook is hanged heavily. Please make me come out of this situation.
    Is the lines Application.ScreenUpdating = False
    Application.EnableEvents = False to be typed twice

    Also, should this code be pasted in Module?
    Last edited by bittubadri; 07-14-2022 at 12:39 AM.

  46. #46
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    The code supplied will not cause the workbook to hang if you are limited to the ranges shown in the last posted file i.e D4:M31. Nor even with a much larger range.

    Without a copy of the actual workbook, it is not possible to ascertain the cause of the "hang" which is likely to be due to the real-time feeds.

    s the lines Application.ScreenUpdating = False
    Application.EnableEvents = False to be typed twice
    this code is not in the functions I coded
    Last edited by JohnTopley; 07-14-2022 at 12:26 AM.

  47. #47
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    should this code be pasted in Module?

  48. #48
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Yes: in a general module NOT in a sheet(s).

  49. #49
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,
    I tried to tweak your code to meet my requirement, but failed. The ‘tweaked’ code you will find inserted in the file attached.
    My requirement:
    1. Code should find the cell in D10:M10 with last “1”
    2. Corresponding ‘cells’ in D4:M4 & D6:M6 (here K4 & K6)..allow me to call K4 & K6 as ‘base cells’ for further correspondence purpose only
    3. In 4th row (corresponding to K4), check the ‘1st cell’ on its left hand side (J4 in this case) findhigh=IF(AND(J4>K4,J6<K6),J4,check ‘2nd cell’ on its left hand side)
    findlow=IF(AND(J4>K4,J6<K6),J6,check ‘2nd cell’ on its left hand side)
    check ‘2nd cell’ on its left hand side=IF(AND(I4>K4,I6<K6),I4) for findhigh & =IF(AND(I4>K4,I6<K6),I6) for findlow
    4. IF no cells in D4:J4 (in this case up to J4 since the corresponding base cell is K4) meets the criteria, then ‘base cells’ becomes J4 & J6 for code’s further checking purpose.
    5. Follow criteria #3 i.e. check the ‘1st cell’ on left hand side (I4 in this case)
    findhigh=IF(AND(I4>J4,I6<J6),I4,check ‘2nd cell’ on its left hand side)
    findlow=IF(AND(I4>J4,I6<J6),I6,check ‘2nd cell’ on its left hand side)
    check ‘2nd cell’ on its left hand side=IF(AND(H4>J4,H6<J6),H4) for findhigh & =IF(AND(H4>J4,H6<J6),H6) for findlow
    6. Follow criteria #4 i.e. IF no cells in D4:I4 (in this case up to I4 since the corresponding base cell is now J4) meets the criteria, then ‘base cells’ becomes I4 & I6 for code’s further checking purpose….& so on
    7. findhigh=’Null’ & findlow=’Null’ IF no criteria is met (example shown in row #36 & 38)

    Please help. I tried but was unable to write the correct code (wrong answers in row #12 & 14; row #28 &30)
    Attached Files Attached Files

  50. #50
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    I am doing no further work on this as the rules change every time..
    Last edited by JohnTopley; 07-15-2022 at 12:34 PM.

  51. #51
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    These conditions will not change any more & is final. Code does 80% of the job...only some additions/modifications to the code will make it complete.

  52. #52
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Post Cell value dependent on multiple conditions

    2 input ranges are there in my Worksheet (tab named ‘HL’)
    Range 1: D10:M10 which generates either of 1 or 0 or “” (null) with a condition that 1 would be generated in a ‘contiguous’ manner i.e. if 1 is generated in K10 then D10:J10=1

    Range 2: 9 sets with each set of 2 rows. The 9 sets are D4:M6; D12:M14; D16:M18; D20:M22; D24:M26; D28:M30; D32:M34; D36:M38 & D40:M42. These 9 sets (with 2 rows each) generates a numerical value >=0 or “” (null)

    Answers needed in 9 ranges (Range 3) each having 2 rows. 9 ranges (Range 3) are T4 & T6; T12 & T14; T16 & T18; T20 & T22; T24 & T26; T28 & T30; T32 & T34; T36 & T38; T40 & T42

    Criteria’s:
    1. Code should find the cell in D10:M10 with last “1” (here in example K10)
    2. Then, corresponding ‘cells’ in Range 2:D4:M4 & D6:M6 (here K4 & K6)..allow me to call K4 & K6 as ‘base cells’ for further correspondence purpose only & similarly for other 8 sets of Range 2 i.e. D12:M12 & D14:M14 (here K12 & K14) & so on up to ……. D40:M40 & D42:M42 (here K40 & K42)
    3. In 4th row (corresponding to base cell K4), check the ‘1st cell’ on its left hand side of K4 (J4 in this case) findhigh=IF(AND(J4>K4,J6<K6),J4,check ‘next cell’ on its left hand side)
    findlow=IF(AND(J4>K4,J6<K6),J6,check ‘next cell’ on its left hand side)
    check ‘next cell’ on its left hand side=IF(AND(I4>K4,I6<K6),I4) for findhigh & =IF(AND(I4>K4,I6<K6),I6) for findlow
    4. IF no cells in D4:J4 (in this case up to J4 since the corresponding base cell is K4) meets the criteria, then ‘base cells’ becomes J4 & J6 for code’s further checking purpose.
    5. Follow criteria #3 i.e. check the ‘1st cell’ on left hand side of J4 (I4 in this case)
    findhigh=IF(AND(I4>J4,I6<J6),I4,check ‘next cell’ on its left hand side)
    findlow=IF(AND(I4>J4,I6<J6),I6,check ‘next cell’ on its left hand side)
    check ‘next cell’ on its left hand side=IF(AND(H4>J4,H6<J6),H4) for findhigh & =IF(AND(H4>J4,H6<J6),H6) for findlow
    6. Follow criteria #4 i.e. IF no cells in D4:I4 (in this case up to I4 since the corresponding base cell is now J4) meets the criteria, then ‘base cells’ becomes I4 & I6 for code’s further checking purpose….& so on
    7. findhigh =’Null’ & findlow=’Null’ IF no criteria is met (example shown in row #36 & 38)
    8. findhigh =’Null’ & findlow=’Null’ IF the ‘current’ base cell/(s)=0 or “” (null)

    I tried but was unable to write the correct ‘complete’ code (wrong answers in row #12 & 14; row #28 &30)

    Appreciate your patience.
    Attached Files Attached Files

  53. #53
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Cell value dependent on multiple conditions

    I've copied the duplicate thread to here - please continue this query here in one thread. Thanks.

  54. #54
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions


  55. #55
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Cell value dependent on multiple conditions

    Thank you for letting us know.

  56. #56
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Explain in words (NOT formula) why J12/J14 and and I28/I30 are BASE cells rather then the values in column K

  57. #57
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    I’ll try my best:
    1. In the sample taken, last “1” is found in K10.
    2. Now the code has to ‘find’ 2 cells: findhigh (from row4) & findlow (from row6) from D4:J6 which should satisfy AND(findhigh>K4,findlow<K6).
    3. This ‘find’ action must start from the column on the left hand side next to the base cells (K4 & K6) i.e. ‘find’ action must start with column J, first.
    4. Evaluate J with K i.e. If AND(J4>K4,J6<K6)=TRUE then findhigh=J4 & findlow=J6
    5. If AND(J4>K4,J6<K6)=FALSE, then find’ action should ‘move’ 1 column on the left hand side of column J i.e. column I
    6. Repeat step 4 I.e. evaluate I with K i.e. If AND(I4>K4,I6<K6)=TRUE then findhigh=I4 & findlow=I6
    7. Repeat step 5 i.e. If AND(I4>K4,I6<K6)=FALSE, then find’ action should ‘move’ 1 column on the left hand side of column I i.e. column H
    8. Repeat step 4 i.e. evaluate H with K i.e. If AND(H4>K4,H6<K6)=TRUE then findhigh=H4 & findlow=H6…….
    & so on till the step 4 reaches column D & evaluates D with K i.e. If AND(D4>K4,D6<K6)=TRUE then findhigh=D4 & findlow=D6

    9. Up to this, the base cells are (K4 & K6) against which preceding columns are evaluated one by one to get findhigh & findlow. Please note: we are trying to get findhigh & findlow from D4:M16 i.e. the first range set out of total 9 range sets.

    10. But now If AND(D4>K4,D6<K6)=FALSE, the ‘base cells (K4 & K6)’ will shift to 1 column on the left hand side of K i.e. column J & the new ‘base cells (J4 & J6)’ would be
    11. Repeat step 3; 4; 5; 6; 7; 8; 9 & 10

    Your quote: why J12/J14 are BASE cells rather then the values in column K

    My answer: Code has completed 1 cycle (step 3 to step 9) to get findhigh & findlow by keeping the base cells (K12 & K14). Step 10 i.e. If AND(D12>K12,D14<K14)=FALSE, the ‘base cells (K12 & K14)’ got shifted to 1 column on the left hand side of K i.e. column J & the new ‘base cells (J4 & J6)’ would be……here step 4 will give the CORRECT answer findhigh=I12 & findlow=I14

    Your quote: why I28/I30 are BASE cells rather then the values in column K
    My answer: Code has completed 2 cycles (step 3 to step 9) to get findhigh & findlow by keeping the base cells (K28 & K30) & then by keeping the base cells (J28 & J30). Step 10 i.e. If AND(I28>J28,I30<J30)=FALSE, the ‘base cells (J28 & J30)’ got shifted to 1 column on the left hand side of J i.e. column I & the new ‘base cells (I28 & I30)’ would be……here step 4 will give the
    Sir for your kind perusal please.

    Note:
    1. If no 2 results are found the findhigh=Null & findlow=Null
    2. findhigh =’Null’ & findlow=’Null’ IF the ‘current’ base cell/(s)=0 or “” (null) answer findhigh=H28 & findlow=H30
    Last edited by bittubadri; 07-16-2022 at 11:25 AM.

  58. #58
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Only explanation ever needed: if we get to "NULL" then decrement n i.e. move 1 place to left, and repeat process. Simple ????

    [
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 07-16-2022 at 12:28 PM.

  59. #59
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,

    This code is working up to 1 in K10.

    I punched L10=1 (last “1”). Punched some values in L4 & L6; L12 & L14 & so on till L36 & L38; L40 & L42. Here intentionally I kept HIGHEST value in the 1st row of each ranges i.e. L4 (for range D4:M4) & other L (for other ranges). T4 should have given Null (correct answer); but it gives some other values.

    T4 & T6; T12 & T14; T16 & T18; T20 & T22; T24 & T26; T28 & T30; T32 & T34; T40 & T42 gives wrong answers (for the values punched in L, these should have given Null as CORRECT answer.

    VERY VERY SURPRISINGLY: T36 & T38 gives CORRECT answers.
    Please see the attached file with only L changed.
    Attached Files Attached Files

  60. #60
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Please Login or Register  to view this content.

  61. #61
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,
    What a great victory. The code works.
    The code is in ‘active’ mode always. Can we make the code to Wait till 1 is found in a cell address, can be B2, to control is ‘active time period’?

    Plus
    In the sample Workbook sent to you, when all D10:M10=0, column T=Null (correct)
    But in my real Workbook, when all D10:M10=0, column T=#NAME?

    I have been breaking my head to solve this but not able to do so. Why #NAME? in the real Workbook? What is the solution please?
    Last edited by bittubadri; 07-17-2022 at 03:19 AM. Reason: Updated

  62. #62
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    #NAME? usually caused by mis-typing of a variable name e,g Finhigh rather than Findhigh. Or variable does not exist or code not in workbook
    ,
    Click on cell and Formula>>Evaluate formula.

    Rehaving a "trigger" for formula: why ? as once triggered, results will remain until next "trigger".

  63. #63
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,
    Problem of #NAME? solved.
    No need for rehaving a “trigger” for the formula.

    Tomorrow the code would get tested in the real environment with real time data feeds. I intrusive thought is bothering me…that when the code would find only D10=1 in D10:M10, how the function =findhigh($D$4:$M$4,$D$6:$M$6,$D$10:$M$10) would ‘deal itself’ i.e. the function would find D10=1 against $D$10:$M$10 BUT the 2 cells D4 & D6 (base cells) would get itself ‘compared’ to which 2 cells???
    Should the code need to be adjusted accordingly to deal with this situation?
    In such situation i.e. when ONLY D10=1 in D10:M10 then findhigh=D4 & findlow=D6
    Last edited by bittubadri; 07-17-2022 at 07:20 PM.

  64. #64
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Please Login or Register  to view this content.

  65. #65
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,

    I did exactly same in your code & also for findlow (I just followed your code’s path & did it…I am no where like you)
    I am not at all expert in vba.
    Today the Workbook ‘was not hanged’ but there are several other Worksheets in this Workbook (may be approximately 18 ws) which has ‘Worksheet codes’ like Private Sub Worksheet_Calculate() & in 2 other Worksheets the codes are…which starts with sentence ….Private Sub Worksheet_Change(ByVal Target As Range).

    No sooner the ‘time’ started & D10 populated “1’ in it in the range D10:M10, ALL CODES IN ALL OTHER WORKSHEETS ‘STOPPED WORKING’.

    At that moment, though your code inserted in the ‘Module’ of the Worksheet was very much required….& your code was functioning well………..but there was no other choice left with me other than to delete your code from the Worksheet….& then re-started the Workbook & then ALL OTHER CODES in all other Worksheets started ‘working’.

    I have no idea as to why this happened…..
    Your code is very much required by me but I am stuck what to do?
    Currently, I have deleted your code & kept some copies of the Workbook.

    Please do help John.

  66. #66
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Without access to your workbook, we won't be able to help. How is D10 populated _ manual entry or via code?

    It suggests the issue is related to Worksheet events code (Worksheet_Change etc).

  67. #67
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    D10 has a simple formula "=Time!C32" & similarly E10:M10.
    Can it be that the code needs to be written with the word "Worksheet" like.....n= Worksheet.Application.CountIf(c, 1) should be used? or more clearly along with the tab name of the Worksheet i.e. ZZZ?

    Do you want me to share the 2 Private sub Worksheet _Change(ByVal Target as Range) codes?
    Updated.....the Worksheet is Sheet93; for your kind perusal
    Last edited by bittubadri; 07-18-2022 at 02:10 PM.

  68. #68
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Try the attached ...

    Please Login or Register  to view this content.
    Last edited by JohnTopley; 07-19-2022 at 01:02 AM.

  69. #69
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    Certainly & I would report back the outcome

  70. #70
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    4 things:
    1. In the lower portion; it is written
    hv = a(n): lv = b(n)

    If n = 1 Then
    findlow = CStr(b(n))
    GoTo finish
    End If

    2. In the upper portion; it is written
    If n = 1 Then
    findlow = CStr(a(n))
    GoTo finish
    End If

    hv = a(n): lv = b(n)
    Is it okay?

    3. End Function should be written in the last most line or not?
    4. In the upper portion
    findhigh = "Null"
    finish:

    In the lower portion
    finish:
    findlow = "Null"
    Is it okay?
    Last edited by bittubadri; 07-18-2022 at 03:00 PM.

  71. #71
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Why don't you test it!

    it was changed so that this ..

    Application.EnableEvents = True
    is executed as this impacts any Worksheet_events code

    These are TWO separate functions: you added the Application.EnableEvents = False / Application.EnableEvents = True code earlier but in the wrong places!
    Last edited by JohnTopley; 07-18-2022 at 03:14 PM.

  72. #72
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    PLEASE do not change any code!!!!

  73. #73
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    Okay
    I have kept sequence as
    findhigh="Null"
    finish:

    &

    findlow="Null"
    finish:

    Hope I did correctly

  74. #74
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Why are you changing the code ? Simply copy and paste into workbook.

  75. #75
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    Okay done exactly same

  76. #76
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    I pasted your latest code, as it is without any change, in the sample Workbook’s Worksheet (without real time feeds) In this I manually changed D10=1 while kept E10:M10=0, the code WORKED CORRECTLY.

    But next step when I changed manually E10=1 also (so that D10:E10=1 while F10:M10=0), the code shows error message box “Compile error: Expected End Function

  77. #77
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Please Login or Register  to view this content.
    My typo BUT you should have been able to identify.
    Attached Files Attached Files
    Last edited by JohnTopley; 07-19-2022 at 01:16 AM.

  78. #78
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Sir,

    It WORKS. I had identified & added the “End Function” & pasted YOUR LATEST CODE AS IT IS. In the Module

    I am taking the T column (findhigh & findlow) of all ranges to another Worksheet in the same Workbook. But I am unable to format these numerical values….example if T4 (findhigh has generated 494.7, the Worksheet’s cell where I have taken this value (494.7), I am trying to format this cell to 2 decimal places but it does not get formatted to 494.70!!! It remains as 494.7

    Rest I will report back in the evening.

  79. #79
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Try

    Please Login or Register  to view this content.

    Set column "T" to GENERAL format BUT the functions return the results as TEXT to cater for returning the (text) "NULL" condition

    If you need to use the results i.e column "T" in any calculations, you will need to "convert" back to number.
    Attached Files Attached Files
    Last edited by JohnTopley; 07-19-2022 at 05:19 AM.

  80. #80
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    John,
    I would like to describe today’s scenes when the excel Workbook was opened & real time data started coming in.
    In the Worksheet, D10=1 IF(9:15 <=NOW<3:30); similarly E10=1 IF(9:30 <=NOW<3:30) & so on till M10. Till then entire D10:M10=0; it becomes 1 one by one from D10 till M10.

    At 9:15, D10=1, the wb was hanged & my mouse cursor (arrow shaped) turned into a spinning blue circle. It happened in all ws (this is my guess because I was not able to move from 1 ws to another). The ws were flickering & the cells along with the values were also flickering though the values were updating & as per the excel functions it was performing.

    This ‘scene’ kept on until F10 became equal to 1 i.e. when time>= 10:00
    Till then (up to time 10:00, i.e. D10=1 or E10=1) your code, PROBABLY, was not running correctly because when E10=1, I noticed all findhigh & findlow in column T were #VALUE! even when it was ‘required’ to populate some values. Here I would say, at D10=1, I could not check the column T.

    After>=10:00 i.e. when F10=1, every things became ‘NORMAL’. Hanging, flickering & #VALUE! in column T had ‘vanished’ & it was ‘NORMAL’ thereafter.

    Do we need Application.Calculation property like
    Application.Calculation = xlCalculationManual
    Application.CalculateBeforeSave = True; etc
    Comments please.

  81. #81
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    I am finished with this thread as you constantly change the parameters: apparently we are now dealing with DATE/TIME and real time data.

    DATE/TIME [NOW()] is numeric and will NOT result in #VALUE errors

    And I cannot simulate the real time data situation (plus any other worksheet event macros which may or may not impact performance).
    Last edited by JohnTopley; 07-21-2022 at 02:19 AM.

  82. #82
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Sir John,
    Nothing has been changed. D10:M10 still has the same criteria as well as other cells. I just divulged ‘how’ D10:M10 becomes 1 from 0. By default they are “0” & time function in other worksheets, to which they are linked, make them “1”; one by one. D10=Time!C32, E10=Time!C56……& so on. This I told you so that if it can help you/us to come out of the situation. Can it be justified as I am changing parameters?

    Sir you are master & I can’t compel you for anything.

    The problem still persists when D10:E10=1 & as soon as F10=1, all problems vanish.

    The problem ‘identified’ is all T columns become #VALUE! even when the conditions are met (when E10=1). Here I would definitely say, that I observed today, that ‘sometimes’ column T populated desired values when E10 was “1” but again it became #VALUE!

    My guess: When E10=1, the code finds n=2, but then it also makes i=0 somewhere & there is no a(0) or b(0)…which might be giving #VALUE! Sir this is my guess & I am nowhere in comparison to gurus like you.

    Can you please make the code act ‘straight’ & give findhigh & findlow in T when n=2 (like you did when n=1). From n=3, the codes can continue in its form.

  83. #83
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    If E10 is 1 then D10 must be 1 also (?) and this does not cause a problem as it will look (backwards) at D4:D6: when n=2, it loops from n-1 to 1 ie, 1 to 1. This works!!!

    It has worked with all the tests so you are doing something different.

  84. #84
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    If E10 is 1 then D10 must be 1 also (?) and this does not cause a problem as it will look (backwards) at D4:D6: when n=2, it loops from n-1 to 1 ie, 1 to 1. This works!!!

    It has worked with all the tests so you are doing something different.

    If E10 is 1 BUT D10 is 0 then it will be incorrect as the code assumes CONTIGUOUS 1s !!!

  85. #85
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Your quote:
    If E10 is 1 then D10 must be 1 also YES

    If E10 is 1 BUT D10 is 0 IT WILL NEVER HAPPEN
    Instead of
    Please Login or Register  to view this content.
    should it be
    Please Login or Register  to view this content.

  86. #86
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    But as you are obviously the expert .... why do you think it has worked so far ??????

  87. #87
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Just want to understand (since I am currently grippling with the same problem)
    your quote: does not cause a problem as it will look (backwards) at D4:D6: when n=2, it loops from n-1 to 1 ie, 1 to 1. This works!!!
    If the code's sentence is FALSE
    Please Login or Register  to view this content.
    what will be the Next i (for n=2)

  88. #88
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    I am a big ZERO in writting code especially analyzing sentences of the code. It may be then n = Application.CountIf(c.Value, 1) is NOT REQUIRED, Sir

  89. #89
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    I explained that in post #84: now leaving the thread.

  90. #90
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Sir Your code in post#79
    Please Login or Register  to view this content.
    What I am using (IS THERE ANY DISCREPANCY) if you also check I would be more satisfied
    Please Login or Register  to view this content.

  91. #91
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Cell value dependent on multiple conditions

    @bittubadri

    Administrative Note:

    Welcome to the forum.

    Unfortunately, it has come to our attention you have violated Rule #8 of our Forum RULES:

    Don't private message, visitor message or email Excel (or Access, Word, etc.) questions to moderators or other members.

    All questions and answers will benefit other posters like yourself when discussed in public threads. The point of having a public forum is to share solutions to common (and sometimes uncommon) problems with all members.

    Breaking this rule is considered harassment by most of our contributors and thus cannot be tolerated. Repeat offense could lead to a permanent ban, so do take this caution to heart.

    Post your question in a public thread and our many contributors will come to your assistance, especially if the title is accurate (see Rule #1) and you include a sample desensitized workbook that makes it easy for others to try and help.
    Dave

  92. #92
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Sir,
    This is one of my last efforts.
    I checked & found:
    All a & all b in this Worksheet (tab named ZZZ) i.e. D4:M4 & D6:M6; similarly D12:M12 & D14:M14……& so on till D40:M40 & D42:M42 ‘can get’ null OR zero OR a numerical values (since they are getting values from another ws which can generate null OR zero OR a numerical values)

    Can this be the ‘cause’ of #VALUE! & hanging/flickering
    Now yours………

  93. #93
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Invalid data (null) will cause #VALUE erorrs.

  94. #94
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Will keep this rule also in mind & I'll never do any private messaging..Sorry for the trouble

  95. #95
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Okay after seeing your reply I have 'dared' to re-furbish 'your' code. I don't know whether it is correct or not. If you permit I'll post the re-furbished code for your kind perusal, Sir

  96. #96
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    The re-furbished code is...for your kind perusal.
    Please Login or Register  to view this content.
    Last edited by bittubadri; 07-21-2022 at 02:56 PM.

  97. #97
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    To reply we need to the EXACT conditions which can arise, especially where a zero or null can occur. For example can either be in the middle of a set of data ......

    so can we have 10,2, 0,30,null,70 ? or any other combination

    The code is very "messy" which why we need to know the above.

    Put together a test file with ALL possible conditions and expected results. For example if n=1 AND value=0 what is result?
    Last edited by JohnTopley; 07-21-2022 at 03:25 PM.

  98. #98
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    your quote
    can we have 10,2, 0,30,null,70 ? or any other combination ONLY +ve numericals OR 0 (zero) is possible. Null or spaces will never come in the data set.
    So with this, do you 'see again' any problem if 0 populates for few seconds & than followed up by a numerical number. But once a numerical number comes, zero will not come in that cell
    UPDATED
    Example If D4=65 & D6=35; E4 can 'start' by getting 0 (zero) & thereafter E4 WILL GET a positive numerical value & 0 (zero) will not come back again in E4. IF E4 'starts' with a positive numerical value than 0 (zero) will not appear in E4. Null or space/(s) WILL NEVER appear in E4. Similarly for all other cells in a & b Range.............INCLUDING D4 & D6

    D10:M10 is 0 by default. FIRST D10 will get 1 & E10:M10=0; than E10 will get 1 i.e. D10:E10=1 & rest F10:M10=0...& so on. D10:M10 WILL NEVER get Null or Space/(s)...
    Last edited by bittubadri; 07-21-2022 at 09:36 PM. Reason: Updated

  99. #99
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    ONLY +ve numericals OR 0 (zero)
    then the original code should work. BUT I don't know the affect of (nor can I simulate) the dynamics of a real-time data feed.

  100. #100
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    It works but when D10=1 and then when E10=1, column T ALSO generates #VALUE! (now for 3-4 seconds) & Then the desired value. When #VALUE! is generated (in either of D10 or E10, although if E10=1 then D10 WILL BE 1), hanging + cursor becoming blue spinning ball.
    From F10=1, every thing is NORMAL. This is I am unable to 'catch the reason'.

    Problem starts when D10=1 & persists only up to E10=1 (of course D10=1 then)

  101. #101
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Sir,
    Currently I am using your code & it is working very nicely...Currently H10=1 i.e. n=5 D10:H10=1; rest I10:M10=0. Column T is not generating #VALUE! neither hanging/cursor becoming blue spinning ball is happening.

  102. #102
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    The problem persists till F10 is not equal to 1.After that code runs smoothly.
    It implies that code is unable to 'adhust' itself when AND((D10=1 OR E10=1),F10 is not equal to 1)
    By adjusting I mean that probably the code loops sometimes into a problem....
    so if the code is written in '2 parts':
    When F10 is not equal to 1 then get findhigh & findlow (here Do While....n<3.....Loop)
    When F10=1 then get all findhigh & findlow (here Do While....n>=3....Loop)
    I think it should solve the problem Sir
    Last edited by bittubadri; 07-22-2022 at 10:18 AM.

  103. #103
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    It behaves correctly if ONLY D10=1 and equally well if BOTH D10 and E10=1 and F10 onwards are 0.

    That's it!!!!!!!

  104. #104
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427
    I think if the code is re written
    If n>=3 Do While ...Loop
    If n=2, straight checks & straight answers (no loops)
    If n=1, straight answers (no loops)
    This would solve the problem

  105. #105
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Well, re-write it as it works all tests I have done on values in D10 and E10.

  106. #106
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Tried..for your kind perusal
    Please Login or Register  to view this content.
    Last edited by bittubadri; 07-22-2022 at 02:44 PM. Reason: Updated

  107. #107
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,208

    Re: Cell value dependent on multiple conditions

    Logically ... no change apart from n=0 check.

  108. #108
    Forum Contributor
    Join Date
    10-18-2019
    Location
    Mumbai
    MS-Off Ver
    OFFICE 2010
    Posts
    427

    Re: Cell value dependent on multiple conditions

    Sir,
    I am not at all good in writing codes. Even this did not worked!!! Even for n=1 (ONLY D10=1 that too punched manually for trial purpose), it does not give findhigh & findlow in column T.........could not solve.....I tried....need your help.....this code is very important for me to run 'smoothly'.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Create 7 dependent dropdown using data validation based on multiple dependent columns
    By b_raj_kumar in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 11-07-2021, 05:20 PM
  2. Cell value dependent on values of multiple cells
    By alfgrey in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-19-2018, 03:43 AM
  3. Dependent drop-down list with if conditions
    By saleemp5678 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2017, 08:31 AM
  4. Multiple warning messages dependent on Cell value
    By mdimiller in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2013, 03:31 AM
  5. Replies: 1
    Last Post: 01-10-2013, 04:27 AM
  6. Show value of a cell dependent on two other cells? Two If conditions?
    By lorne17 in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 09-27-2012, 09:36 AM
  7. Replies: 2
    Last Post: 04-14-2011, 08:12 PM

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