+ Reply to Thread
Results 1 to 9 of 9

Insert a formula with relative cell reference based on a number in a column

  1. #1
    Registered User
    Join Date
    07-01-2007
    Posts
    6

    Insert a formula with relative cell reference based on a number in a column

    Hello,

    I would love it if somebody smarter than me could help with this. I need a macro. I have 2 columns A & B. In column A I have set amounts that don't need to change. In column B each cell adds the cell above it and the cell to the left in column A.

    Certain cells in column B have a number 1-12. I need to input 1 of 12 different formulas based on what number is in the cell, without changing any of the other cells beyond adding the new amount.

    I'm not very good with VBA yet so all my attempts at cooking something up are failing miserably.

    If it would help I will upload a sample of what I'm talking about. Any help would be greatly appreciated.

  2. #2
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    If I understand your post correctly you want the formula to calculate the value of cell B2 based on what value is in Cell B1 using the value of cell B1 and A2.

    Have your code cycle through all the populated cells in column B and have it determine which of your 12 formulas to use based on the value in column one row up.

    Give this a try and see if it's what you are after.

    Please Login or Register  to view this content.
    HTH

  3. #3
    Registered User
    Join Date
    07-01-2007
    Posts
    6
    Sorry, I knew I wasn't explaining that very well.

    Column B has a wide range of numbers, but I only need to input one of the 12 formulas if the number in the active cell in column B is between 1-12.

    The number 1-12 in the active cell will determine what formula is entered. Then it just needs to continue doing that until it gets to the end of the sheet. If the value in the cell is not a number 1-12 it needs to leave the cell alone. Thanks a lot for the help.

  4. #4
    Registered User
    Join Date
    07-01-2007
    Posts
    6
    Figured it out! Thanks so much. What you posted wasn't exactly what I wanted but with a little tweaking I got it to work. Thanks again for the help.

  5. #5
    Registered User
    Join Date
    07-01-2007
    Posts
    6

    Angry New challenge

    I'm having another problem with this same worksheet. It would be to hard to explain without some kind of visual aid, so I included a sample worksheet, with the explanation written in. Any help would be greatly appreciated.

    P.s. I tried to include my current macro in the workbook but I'm not sure that i did it right. So I have included it in this post as well.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Dcritelli; 07-15-2007 at 01:38 PM. Reason: added example worksheet

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    No attachment

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  7. #7
    Registered User
    Join Date
    07-01-2007
    Posts
    6
    Should be there now. Forgot initially.

  8. #8
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    Here is a slightly different approach which incorperates your formula. I'm not sure if it will work with your second problem you detail in your example spreadsheet but give it a look. It is difficult to figure out what you want the sheet to do and what you have already manually updated the sheet to do (i.e. which formulas were added by the macro and which you added) in your example. My code does not repeatedly select the next cell and simply loops from the second cell to the last cell. This is more efficient when the code is running.

    Please Login or Register  to view this content.
    Additionally, it appears that your approach is to manually enter the number of months between calculating fixed and adjusted amounts.
    Since you have the date in column B why not just have the macro determine the interval and use that in the calculation?
    That would eleminate the Month and Change columns from your sheet and you also would not have to manually go through and enter if the month has changed.

    HTH
    Last edited by bhofsetz; 07-16-2007 at 05:03 PM.

  9. #9
    Registered User
    Join Date
    07-01-2007
    Posts
    6
    Since you have the date in column B why not just have the macro determine the interval and use that in the calculation?
    That would eleminate the Month and Change columns from your sheet and you also would not have to manually go through and enter if the month has changed.
    That's the only way I could figure out how to get the macro to work the way I needed it too. I'm not very good with VBA; I'm much better with formulas in the actual worksheet. Thus, I did as much as I could in the spreadsheet then I automated the rest.

    Regardless I've got it to a point now where I only have to do the last part I detailed in the example. This is slightly more manageable to do manually. Thanks for the work you put into helping me, I really appreciate it.

+ 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