+ Reply to Thread
Results 1 to 14 of 14

Mathematical operations with variables using loops

  1. #1
    Registered User
    Join Date
    03-14-2011
    Location
    Linköping, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    8

    Mathematical operations with variables using loops

    Hello,
    i have tried to write a VBA code for Mathematical operations on columns with a variable using loops. i am unable to figure out how to rectify the code.
    my work involves forecasting of monthly production. i have the monthly production data from
    March-June. if there is a small increase the forecast for June say x % ( x is a variable ). i should be able to produce data in this manner.
    Forecast for June = Column June + (x*Column June )/100.
    I have written the code for this .but i am having some serious errors.
    any help will be appreciated

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sandeep830808; 04-05-2011 at 09:03 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Mathematical operations with variables using loops

    So are you wanting to overwrite the old values , in a month column, with the new values ?.. ie. loop thru every number in a column and update that number by using you caclulation ? Or.... are you wanting to view a total for column based on change ? In other word what are you expecting for results ?
    Last edited by nimrod; 04-03-2011 at 08:07 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Mathematical operations with variables using loops

    This code will update the numbers in a specified column . By-The-Way .. excel has a built in feature for doing just that i.e. the Muliply feature on the "PasteSpecial" window is for this very type of thing.

    Please Login or Register  to view this content.
    Last edited by nimrod; 04-03-2011 at 08:44 PM.

  4. #4
    Registered User
    Join Date
    03-14-2011
    Location
    Linköping, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Mathematical operations with variables using loops

    Hello Nimrod,
    thank you for your help. I have another question . what if i wanted to paste the results in another column instead of overwriting on the same column. Any suggestions ?

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Mathematical operations with variables using loops

    Could you be more specific ? There are many ways this could be done , and each way would be different codine ... for exampe
    -- at run time you tell macro month and indicate where to paste results
    -- The macro always paste to the same predetermined column
    -- The macro inserts a column beside the old data ( though this would mean changing how you prompt for the months column since they'd be dynamic

  6. #6
    Registered User
    Join Date
    03-14-2011
    Location
    Linköping, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Mathematical operations with variables using loops

    Hello Nimrod,
    Thanks for your help. i want the Forecast Data for March Displayed in column R, April in Column S...and so on. By doing this i can actually see the original data in columns L to Q, and the forecast change from Columns R to W. Any suggestions about how to do this.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Mathematical operations with variables using loops

    Put the month you want to forecast in A1 (jan=1, feb=2, etc)
    Put the percentage you want to use in the forecast in A2 (1,30,90,120,250, etc)
    This macro stores the result in column AA, AB, AC, etc

    Please Login or Register  to view this content.



  8. #8
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Mathematical operations with variables using loops

    To see changes just follow "ResultColumnOffset "

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-14-2011
    Location
    Linköping, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Mathematical operations with variables using loops

    Hello Nimrod,
    Thanks for the help. the code works but there is a little mix up.
    The source columns are also getting updated along with the target columns .
    The code copies the source column, and paste it in the Target column. then updates both of them.
    I source column should not get updated, only the target column should be updated. I tried various changes but none seems to work. Can you suggest some change.

  10. #10
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Mathematical operations with variables using loops

    How's this ?

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-14-2011
    Location
    Linköping, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Mathematical operations with variables using loops

    hello Nimrod,
    Thanks once again.The code works only for the Month of March i.e 3, and doesn't seem to work for the others. I am clueless to what's wrong in the code.

  12. #12
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Mathematical operations with variables using loops

    OOPPSS sorry "MonthNum - FirstMonthNum" was inverted and it was moving to the left , instead of to right , for each month added.. sorry


    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    03-14-2011
    Location
    Linköping, Sweden
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Mathematical operations with variables using loops

    Hello Nimrod,
    Thanks once again, Now the code works perfectly. My VBA skills are not that advanced. This helped my learning too.

  14. #14
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Mathematical operations with variables using loops

    My pleasure ... please let me know if you'd like any lines explained ... to aid in your education of VBA.

+ 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