+ Reply to Thread
Results 1 to 10 of 10

insert formula based on cell entry using vba

  1. #1
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    insert formula based on cell entry using vba

    i'm sure this can be done but i cant get an angle on the method. i want to use VBA to put a formula into cell G3 based on the users entry in cell D3 so, for example the user enters M in cell D3 and the VBA code puts the formula "if D3="M",A3,0"into cell G3

    i know i could use a formula in the cell but i want it to work with multiple entries so i figure VBA is the way to go

    if i could get an idea what to start with i could probably figure out the rest but i'm stuck. any help appreciated

    thanks
    Last edited by jimb0693; 10-11-2009 at 05:32 AM. Reason: problem fully sorted now

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: insert formula based on cell entry using vba

    Maybe something along this line:

    Please Login or Register  to view this content.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    Re: insert formula based on cell entry using vba

    thanks for your help palmeto, worked a treat, i should be able to add the rest to it. thanks again

  4. #4
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    Re: insert formula based on cell entry using vba

    sorry i was a bit premature with this, comes from being awake in the middle of the night and not being thourough, the code is fine except it works only on the row specified, how would i extend it to run to the bottom of the worksheet?

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: insert formula based on cell entry using vba

    Change

    Please Login or Register  to view this content.
    to be

    Please Login or Register  to view this content.
    Change the ROW number in the above as required (remove if not required) - ie above works on all of D with exception of changes made to D1 which it eg assumes header row

  6. #6
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    Re: insert formula based on cell entry using vba

    sorry but i'm really stuck with this now, i also need to change this line to run all the way down but everything i've tried has failed, help please!

    Please Login or Register  to view this content.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: insert formula based on cell entry using vba

    Try this:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

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

    Re: insert formula based on cell entry using vba

    Is this what you want?
    Please Login or Register  to view this content.
    Hope that helps.

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

    Free DataBaseForm example

  9. #9
    Registered User
    Join Date
    12-29-2005
    Posts
    90

    Re: insert formula based on cell entry using vba

    thanks for the help guys, i tried jbeaucaire's suggestion and it worked perfectly so, sorry royuk i didnt try yours, but the help is appreciated anyway, a huge THANK YOU to all.

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

    Re: insert formula based on cell entry using vba

    That code only put's one formula in, you need the Select case to put in different formlas.

    Also, the target.Count >1 will stop the code attempting to run if several cells are selected, and the Intersect part makes the code work only on Column D from D3 down.

+ 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