+ Reply to Thread
Results 1 to 15 of 15

Macro to find value between two limits for a given condition

  1. #1
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Macro to find value between two limits for a given condition

    Hello everyone!

    I'm hoping anyone can help me with a problem. I need a macro that finds me a certain value bewtween two preasigned values while a certain condition is met.
    Now these are my values from a sheet in excel
    Please Login or Register  to view this content.
    All these values are known and fixed except Nrd; and i'm looking for ec while Nrd=Ned. The value Nrd depends on the value k, hence it depends on the value ec. The condition for ec is that it must be 0>ec>ecu (ecu is negative). Nrd is calculated in excel in table form.
    I introduced a value G that is an alloved error for the result like abs(G)=abs(Nrd)-abs(Ned). So instead of Nrd=Ned the condition can also be satisfactory if G<0.1 (I assumed this if the calculation takes alot of time), so it's a like a precision limit for ec.
    If needed the ec value can go in a step of let's say 0.0000001 (or smaller if doesn't take too long to calculate).

    Thanks in advance!

    DamirDz

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find value between two limits for a given condition

    attach please the file
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Macro to find value between two limits for a given condition

    Dear patel45

    Here's the file
    Mi-Fi.xlsm
    or here
    http://www.4shared.com/file/yrSEXXOL/Mi-Fi.html

    Thank you!

    DamirDz

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find value between two limits for a given condition

    I can not find any code in your attachment

  5. #5
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Macro to find value between two limits for a given condition

    Dear patel45,

    Here's the file
    Mi-Fi_1.xlsm

    This what I only wrote, i had few tries with if and do functions but i got stuck.

    Thanks!

    DamirDz

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find value between two limits for a given condition

    Please Login or Register  to view this content.
    Last edited by patel45; 06-25-2013 at 12:43 PM.

  7. #7
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Macro to find value between two limits for a given condition

    Thank you very much for your time and effort patel45.
    It would be nice if when have have time just to explain what you exactly did here since I'm new to VBA.

    Thanks again!

    DamirDz

  8. #8
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find value between two limits for a given condition

    Does it solve your problem ?

  9. #9
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Macro to find value between two limits for a given condition

    Yes it does!
    Thanks again!

    Just one more question: what if my value ec is bounded like this 0<ec<ecmax?

    Best regards!

    DamirDz

  10. #10
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find value between two limits for a given condition

    I did not understand your question

  11. #11
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Macro to find value between two limits for a given condition

    Dear patel45,

    I do have some problems, but it's my mistake. The condition doesn't satisfy in some cases because i set the "G" value wrong. this value should be 1.00005<Nrd/Ned<0.99995 instead abs(Nrd)-abs(Ned)<0.1 (or Nrd/Ned=1 in a perfect calculation) this way the function makes sure that Nrd and Ned have the same sign (they can only be both positive or both negative).

    I added one more calculation (i copied your code twice) but this time I'm looking for the value es which can be -0.002<es<esmax (esmax=0.025). But I cannot figure out how to modify the code for this range it blocks at some calculations. In this calculation i used "H" instead of "G", but this should also be Nrd/Ned.
    I'm attaching my file again if you want to see what I did. My english not very well to explain it properly

    Mi-Fi_2.xlsm

    Thank You!

    DamirDz

  12. #12
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find value between two limits for a given condition

    I'm sorry but there is too much confusion for me, I'm seeing 2 calculations in your sheet.

  13. #13
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Macro to find value between two limits for a given condition

    Yes there are 2 calculations: one is looking for ec betwenn 0>ec>ecmin while es is fixed; and the other is looking for es between 0<es<esmax while ec is fixed.
    The calculations are very similar and I have copied everything on the sheet and use different cells for each calculation. In general they are the same. Essentially I used your code twice and nothing more.
    I do only have problems with looking for es : sometimes it makes a correct calculation for certain Ned and sometimes it blocks and cannot converge.

  14. #14
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to find value between two limits for a given condition

    Last edited by patel45; 06-26-2013 at 10:47 AM.

  15. #15
    Registered User
    Join Date
    08-08-2011
    Location
    Zagreb, Croatia
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Macro to find value between two limits for a given condition

    Yes I did, and the solver function works perfectly, but the problem is I cannot "run" solver from other sheets. The excel file here is just a sheet in a bigger excel file I'm making.

    I wanna thank you for your time and effort patel45!

    Best regards!

    DamirDz

+ 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