+ Reply to Thread
Results 1 to 6 of 6

Compile a Value in VBA Instead of Cell

Hybrid View

  1. #1
    Registered User
    Join Date
    07-23-2008
    Location
    usa
    Posts
    10

    Compile a Value in VBA Instead of Cell

    On my worksheet I have a series of formulas in sperate cells as follows:

    Cell F22 =If(A22=1, 2)
    Cell G22 =If(A22=2, 1)
    Cell H22 =If(A22=3, 0)
    Cell I22 =Sum(F22:H22)

    I then use the value in I22 in other functions by using "I22" in their formulas. Is there a way in VBA to perform the same task so I can refer to the value in other formulas without assinging the value to a cell in the worksheet?

    Also, how do I set the macro to always update the calculations when new numbers are entered on the spreadsheet?

    Thanks!
    Last edited by VBA Noob; 08-07-2008 at 02:22 AM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    I do not fully understand what, how & why you want to use VBA if you can use formulas

    You can have a macro run whenever a cell value is changed or when a sheet is calculated. The macro can do actions in the place of formulas.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Use a Named Formula, see

    http://www.tushar-mehta.com/excel/ne..._formulas.html
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    07-23-2008
    Location
    usa
    Posts
    10
    Mudraker,

    I did have a lot of formulas running in several different cells that calculated information that I needed for other displayed cells. Most of the cells containing the formulas do not need to be displayed for the end-user of the worksheet. I initially highlighted all of the cells that contained the formulas that I did not want visible and changed the font color to white so that they would not be displayed. However, this seemed a little cheesy to me and, if the cells were highlighted, would become visible.

    Is there a simple way to hide several formulas that will run in real-time in the worksheet that will not be made visible to the end-user? The reason I went the VBA route was because of this....

    Thanks!

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    You can protect the cells, hide their contents, and protect the workbook - then users will not be able to see the formulas. Nothing you've said so far warrants the use of VBA.

    If you just want to because you want to, that's fine.

  6. #6
    Registered User
    Join Date
    07-23-2008
    Location
    usa
    Posts
    10
    Thank you Shg. I figured that was cheating somehow... Nonetheless, it was a fun learning experience.

+ 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