+ Reply to Thread
Results 1 to 6 of 6

IF THEN with FOR loops

  1. #1
    Registered User
    Join Date
    11-08-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    5

    Thumbs up IF THEN with FOR loops

    Greetings all,

    I am trying to figure out how to use VBA to perform a small calculation based on cell values.

    Let's say I have cells A1, A2 & A3.
    A1 = amount in gold coins
    A2 = amount in silver coins
    A3 = amount in copper coins

    100 copper = 1 silver
    100 silver = 1 gold

    Basically, what I want to do is, IF the number of copper is 100 or greater, then it will add a +1 to the preceding cell, silver. And so on.
    So, if a user enters A1=2, A2=120, A3= 210 then the sheet will automatically display:
    A1=3, A2=22, A3=10

    I hope that makes sense. I have attached a sample table.
    In the sample, a user enters a QTY in E3. The total columns to the right will automatically multiply the QTY * coins for G, S & C.
    If the copper amount comes out to 250, then I want that 200 to be converted to a +2 to the silver total... or a +3 for 300, etc. Same for silver to gold.

    I have tried a couple of different examples found on google, however most of them do not detail how the function is used and I am having a hard time adapting it to what I want it to do.
    The values will ONLY be whole numbers, so no decimals or floats are needed.

    Any help is greatly appreciated.

    Regards.
    Attached Files Attached Files

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,453

    Re: IF THEN with FOR loops

    Administrative Note:

    Hi and welcome
    although we value privacy as much as anyone else, it could be important that members have a rough idea of your location. You might in the future post questions which are bound to your regional settings.
    So, please update your profile to something more precise than "Pluto" ( country will suffice, no need to be more precise).
    Thank you for helping us to help you

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,110

    Re: IF THEN with FOR loops

    How about
    for gold
    =INT((Table1[@G]+(Table1[@S]/100)+(Table1[@C]/10000))*Table1[@Qty])
    silver
    =INT(MOD((Table1[@S]+(Table1[@C]/100))*Table1[@Qty],100))
    copper
    =MOD(Table1[@C]*Table1[@Qty],100)

  4. #4
    Registered User
    Join Date
    11-08-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    5

    Re: IF THEN with FOR loops

    Thanks.

    I've tried to reply to this about 3 times so far, and this forum keeps telling me I cannot reply using links, images or videos... none of which I am trying to use.
    So, hopefully this post actually makes it to the thread.

    Regards.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,110

    Re: IF THEN with FOR loops

    You're welcome & thanks for the feedback

  6. #6
    Registered User
    Join Date
    11-08-2019
    Location
    USA
    MS-Off Ver
    365
    Posts
    5

    Re: IF THEN with FOR loops

    Quote Originally Posted by Fluff13 View Post
    You're welcome & thanks for the feedback
    I had a much longer and detailed reply however, as I stated, it kept not wanting to let me post it.
    So, I got fed up and went simple.
    Did give you + rep though.

+ 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. Loops within loops looping
    By Memphismark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2017, 12:21 PM
  2. VBA Loops
    By Robinkio in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2016, 03:00 AM
  3. VBA Loops
    By Robinkio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2016, 06:50 AM
  4. VBA Loops
    By Robinkio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2016, 05:25 AM
  5. [SOLVED] Two For Next Loops together..
    By ChrisMattock in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2015, 06:32 AM
  6. Loops...
    By Willabo in forum Excel General
    Replies: 2
    Last Post: 06-14-2006, 11:15 AM

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