+ Reply to Thread
Results 1 to 17 of 17

Need help with VBA code - "If untill" and basic VBA

  1. #1
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Post Need help with VBA code - "If untill" and basic VBA

    Hey

    I need some help with a VBA code. I've been trying to make some excel work without VBA, but i came to the conclusion that it isnt possible the way i want it to work withouit VBA code



    I got an excel sheet with 54000 Rows of data. - Raindata

    What i need is as following


    Column T is where i want the data - "Volume of the water in the area"

    what i need each row in T a calculation needs to be made
    fx. in T6 = R6 / 1000 + T5 - But if T6 > 371 it needs to go down with the value in "H2" until T =<0.
    as in T6 is 27 - T7 is 50 - T8 is 350 T9 is 373 - now it has to drop until T0<=0.

    The parameters is as following.
    T = R / 1000 + T-1 (T on row above) if T > 371 then this should be minus H2 until T<= 0. If T > 990 it has to go down with 2*"H2" until T=< 619 where it should only go down with "H2"


    I have no idea if this rambling is understandable? i just really need some help or pointers. i've been trying with google but to no avail so far.
    Attached Files Attached Files
    Last edited by HV.Excel; 11-04-2024 at 06:19 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-04-2017
    Location
    chennai
    MS-Off Ver
    MS OFFICE 365
    Posts
    389

    Re: Need help with VBA code - "If untill" and basic VBA

    Dear HV.Excel

    kindly attached with excel sample data File. so we will able to help you.
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Mark Thread as Solved...

  3. #3
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Re: Need help with VBA code - "If untill" and basic VBA

    I've attached a part of the data now

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,210

    Re: Need help with VBA code - "If untill" and basic VBA

    Quote Originally Posted by HV.Excel View Post
    ... but i came to the conclusion that it isnt possible the way i want it to work withouit VBA code ...
    Have you tried to apply PQ (Power Query) to your goals?

  5. #5
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Re: Need help with VBA code - "If untill" and basic VBA

    i've looked into it, but cant really see how to do it with PQ

  6. #6
    Valued Forum Contributor
    Join Date
    02-04-2017
    Location
    chennai
    MS-Off Ver
    MS OFFICE 365
    Posts
    389

    Re: Need help with VBA code - "If untill" and basic VBA

    Dear HV.Excel,


    In cell T5 assuming row 4 starts the calculation, enter this initial formula:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In cell T6, you can use a more complex IF formula to handle your conditions.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This formula checks if T6 exceeds 990, in which case it subtracts 2 * H2. If T6 is greater than 371, it subtracts H2. Otherwise, it just adds R7 / 1000 + T6 as usual.

    i attached the sample File
    Attached Files Attached Files
    Last edited by sudbhavani; 11-04-2024 at 06:38 AM.

  7. #7
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Re: Need help with VBA code - "If untill" and basic VBA

    Thanks for the reply Sudbhavani

    I've tryed to do the same thing as you've done with a complex If formula.

    The problem is that this wont consider the fact that when T >= 371 it has to subtract H2, untill it hits 0, and not just until the formula is below 371.
    The same for when T = 990, it should subtract 2*H2 untill it's under 619 and not just when it's under 990.

    i think of it as following

    When T > 371 "raise flag"
    When T = 0 "lower flag"

    dont know if this makes sense?

  8. #8
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,210

    Re: Need help with VBA code - "If untill" and basic VBA

    How to calculate the value for cell "T5" ?

  9. #9
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Re: Need help with VBA code - "If untill" and basic VBA

    T5 can be set to 0

  10. #10
    Valued Forum Contributor
    Join Date
    02-04-2017
    Location
    chennai
    MS-Off Ver
    MS OFFICE 365
    Posts
    389

    Re: Need help with VBA code - "If untill" and basic VBA

    Dear HV.Excel

    Starting in T5
    Set an initial value:

    In T5: Enter your starting volume, e.g., 0.
    Formula for T6 enter the following formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In T7, enter the following formula:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,210

    Re: Need help with VBA code - "If untill" and basic VBA

    In posts #1 and #7 you provide different dependencies for the data. Describe them again, uniformly ...

    #1
    "T6 = R6 / 1000 + T5"
    "T = R / 1000 + T-1"
    "But if T6 > 371"
    "If T > 990"

    #7
    "when T >= 371"
    "when T = 990"
    "When T > 371 "raise flag""

  12. #12
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Re: Need help with VBA code - "If untill" and basic VBA

    I might have been unprecise. let me try to make it more precise

    *
    When T < 371 then T = R/1000 + T-1 (the cell above)

    When T >= 371 And T<= 990 then T = R/1000 - H2 + T-1(the cell above) untill T <= 0

    When T > 990 then T = R/1000 - 2*H2 + T-1(the cell above) untill T <= 619
    *


    does this make more sense?
    Last edited by AliGW; 11-05-2024 at 03:24 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead. Please review the forum guidelines.

  13. #13
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Re: Need help with VBA code - "If untill" and basic VBA

    @sudbhavani

    Hmm this is closer to correct, but the value i subtract (H2) is getting smaller and smaller in your fomula
    Last edited by AliGW; 11-05-2024 at 03:25 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead. Please review the forum guidelines.

  14. #14
    Valued Forum Contributor
    Join Date
    02-04-2017
    Location
    chennai
    MS-Off Ver
    MS OFFICE 365
    Posts
    389

    Re: Need help with VBA code - "If untill" and basic VBA

    Dear HV.Excel,

    Thank you for pointing that out! I understand now that you want a constant subtraction of H2
    2xH2 if above 990) until the conditions are met, rather than reducing the subtraction gradually
    Set an initial value in T5. 0
    Change the Formula for T6
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Once you enter this formula in T6, you can drag it down for as many rows as you need. This approach ensures that each cell in column T adjusts based on the thresholds consistently, and once a threshold is hit, the subtraction of H2 or 2×𝐻2 continues until the target values are reached.

    Let me know if this aligns with your needs or if any further adjustments are necessary!
    Last edited by sudbhavani; 11-05-2024 at 01:35 AM.

  15. #15
    Registered User
    Join Date
    10-31-2024
    Location
    Denmark
    MS-Off Ver
    365
    Posts
    8

    Re: Need help with VBA code - "If untill" and basic VBA

    Thanks for the reply

    This meets the first criteria that is needed, but sadly i doesnt help with the big problem i have.
    Once the value of T hits 371, it needs to subtract H2, untill T <= 0. Then it has to stop the subtraction of H2 until T hits 371 again.
    - this is where im unsure if it's possible to do without WhatIF analysis or VBA coding? (since there is no "Until" formula i can use?
    Last edited by AliGW; 11-05-2024 at 03:25 AM. Reason: Please don't quote unnecessarily - use the Quick Reply button instead. Please review the forum guidelines.

  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. 2501 (Windows 11 24H2 64-bit)
    Posts
    89,067

    Re: Need help with VBA code - "If untill" and basic VBA

    Administrative Note re. Forum Guideline #2:

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter and rarely necessary.

    If you are responding out of sequence, it is usually enough just to mention the helper's user name (e.g @AliGW).

    If you do need to quote, limit the quoted section just to the section to which you wish to draw your helper's attention or a direct question to which you wish to respond.

    For normal conversational replies, try using the QUICK REPLY box below or the REPLY button instead of REPLY WITH QUOTE.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  17. #17
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,484

    Re: Need help with VBA code - "If untill" and basic VBA

    The parameters is as following.
    T = R / 1000 + T-1 (T on row above) if T > 371 then this should be minus H2 until T<= 0. If T > 990 it has to go down with 2*"H2" until T=< 619 where it should only go down with "H2"
    Perhaps...taking above parameters into consideration...

    Please Login or Register  to view this content.
    Last edited by Sintek; 11-05-2024 at 03:42 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ 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. Replies: 7
    Last Post: 12-03-2022, 01:31 PM
  2. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  3. [SOLVED] Excel 2010 -- "Visual Basic" "Macros" and "Record Macro" all disabled.
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2017, 06:11 AM
  4. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  5. vba to wait untill , "In Progress" website message to finish/disappear
    By raj soni in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-01-2015, 06:36 PM
  6. Short "Basic" Macro to copy and paste formulas "N" times.
    By gradyhawks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2014, 02:34 PM
  7. [SOLVED] "Macros" and "Visual Basic" in developer tab are locked and not clickable
    By fitkhan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-11-2014, 05:22 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