+ Reply to Thread
Results 1 to 11 of 11

Inputting Formulas into cells using VBA

  1. #1
    Registered User
    Join Date
    12-20-2007
    Posts
    10

    Inputting Formulas into cells using VBA

    I'd like to figure out a way to 'insert' a formula into a specific range of cells using VBA only when the Value of $A$7 is changed to a value that does NOT equal "Custom".

    Heres what I have so far using Worksheet change event....

    Please Login or Register  to view this content.
    As you can see above, I'd like to have '=myfunction(A7)' inputted as a forumla into some cells. Code above gets me into the second If statement, but none of the cells in my range update. Not certain I'm approaching it the right way. Any guidance is appreciated. Thanks. -FM
    Last edited by VBA Noob; 12-28-2007 at 03:58 PM.

  2. #2
    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
    Foboman,

    Remember to wrap your code next time.

    Is the trigger a formula or a by the user changing A7. If it's a user change it works for me

    Try adding this to the start
    Please Login or Register  to view this content.
    and this to the end
    Please Login or Register  to view this content.
    Also is the formula a custom User defined function ??

    If so it might be worth posting that code

    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 !!!

  3. #3
    Registered User
    Join Date
    12-20-2007
    Posts
    10
    VBA Noob, Thanks for the response. See bolded comments below.

    Is the trigger a formula or a by the user changing A7. If it's a user change it works for me

    -trigger is user-initiated. They will be selecting a 'string' from a drop down list in A7.

    Try adding this to the start
    Please Login or Register  to view this content.
    and this to the end
    Please Login or Register  to view this content.
    -added these lines. still dont see any formula populating the cells.

    Also is the formula a custom User defined function ??

    If so it might be worth posting that code

    The formula I want to ppulate the cell is a UDF. Its a simple Case statement function used to evaluate the contents of A7 See below.

    Function quicknetwork(quick1 As String)
    Select Case quick1
    Case "Show All Network Space Available"
    quicknetwork = "ALL"
    Case "Show All Network Space Utilized"
    quicknetwork = "ALL"
    Case "Show ALL Space Available"
    quicknetwork = "ALL"
    Case "Show ALL space Utilized"
    quicknetwork = "ALL"
    Case "Custom"
    quicknetwork = ""
    Case Else
    quicknetwork = "NONE"
    End Select
    End Function
    Let me know if you have any other ideas, suggestions.

  4. #4
    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
    Try this example

    Event Macro Code
    Please Login or Register  to view this content.
    Module Code
    Please Login or Register  to view this content.
    Amended - Or this shorter code
    Please Login or Register  to view this content.
    ThisWorksheet Module To turn on events
    Please Login or Register  to view this content.
    VBA Noob
    Attached Files Attached Files
    Last edited by VBA Noob; 01-02-2008 at 06:12 AM.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Why would you need VBA to do this? An IF formula would work.
    Hope that helps.

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

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    12-20-2007
    Posts
    10
    Thanks for the attachment. I fooled around with it a bit and think I found whats causing the problem. I failed to mention (hadn't thought it relevant), that my A7 cell uses a list to validate entry options. The user will not be 'typing' in values to change this cells contents, but instead, is selecting one from a list. When A7s contents is changed using listed drop down values, the cell range wont take a formula. If I remove the 'list', it all works perfectly. Is there any way to get this working with a list? See my edited attachment below.
    Attached Files Attached Files

  7. #7
    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
    When A7s contents is changed using listed drop down values, the cell range wont take a formula
    Don't understand. Do you want to be able to change the range depending on the answer ??

    VBA Noob

  8. #8
    Registered User
    Join Date
    12-20-2007
    Posts
    10
    whoa..that was fast.

    Nope. The cell Range that I'd like the formula (quicknetwork(a7), inserted into (C13-C27) can stay the same. Your previous spreadsheet demonstrated exactly what i need happening. Just need to make it happen with the change I made to the A7 cell in the spreadsheet I attached above :P. Have a look at it, you'll notice the "ALL, NONE, etc" values throughout C13-27 values dont change. Hope this makes sense.

  9. #9
    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
    Seems to work for me
    If i change cell A17 to "show all network space utilized" C23 updates from None to all.

    VBA Noob
    Last edited by VBA Noob; 01-03-2008 at 10:04 AM.

  10. #10
    Registered User
    Join Date
    12-20-2007
    Posts
    10
    Did you 'type' into A7 or did you use the drop down options? If I start by typing something into A7 and then press enter, the values in C13-27 change as required. If I use the mouse only and select a value for A7 using the pointer from the drop down items, the values in C13-27 dont change. I attached another spread with scenario where the values in C13-27 wont change if I select the contents of A7 using the mouse.
    Attached Files Attached Files

  11. #11
    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
    Your list is longer the items on your function.

    You need to add

    Show All Server Space Available
    Show All Server Space Utilized
    or use the other function

    Please Login or Register  to view this content.
    VBA Noob

+ 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