+ Reply to Thread
Results 1 to 6 of 6

Adding input into cell

  1. #1
    Registered User
    Join Date
    11-05-2020
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Adding input into cell

    Hello,

    I have what would seeming be a simple question but for the life of me I cant fathom it out and Google isn't helping me very much.

    What I am trying to do is have a drop down list when selected it does a VLOOKUP and if it matches a value put that value in the cell two right of it. This works perfectly. However what I want is if there is no match then to run some code to ask the user the amount and then place that in the cell.

    So this is what is currently in the cell:

    =IF(VLOOKUP(B4,Input!$C$1:$D$60,2,FALSE),VLOOKUP(B4,Input!$C$1:$D$60,2,FALSE),AddCost())

    AddCost() is the Function I am having issues with so here it is:

    Please Login or Register  to view this content.
    As yuo can see I am trying to get the input out by using a messagebox for testing but ideally it would need to be in the column two cells to the right so the Vlookup is in Column B and the value should go into the same row on Cell D

    Can anyone see where I am going wrong?

    Thanks

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Adding input into cell

    A User Defined Function (UDF) cannot do the following things you are trying to code.
    • Prompt for input
    • Change the value of a different cell
    • Show a Msgbox

    You could use the Worksheet_Change event procedure

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-05-2020
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Adding input into cell

    Hello,

    Thank you for your response.

    Sorry for being stupid but I have never heard of a worksheet change procedure. Where would I have to put this and where / how do I call it?

    Thanks

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Adding input into cell

    To install the code:
    • Right-click on the sheet tab.
    • Select View Code from the pop-up context menu.
    • Paste the code in the worksheet's code module.

    The code automatically runs when you make a manual change to a cell on the sheet. It tests if that change was to a cell in column B that has a dropdown list. Then it does the VLOOKUP or the Input Prompt thing.

  5. #5
    Registered User
    Join Date
    11-05-2020
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Adding input into cell

    Thank you I have added it in and taken out my IF statement. It does the lookup but doesn't seem to prompt for the input box unfortunately unless I have done something incorrectly?

    Thanks

  6. #6
    Registered User
    Join Date
    11-05-2020
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Adding input into cell

    Hello,

    Thank you for your post after some figuring out of what the code was doing and why it wasn't playing I realised that it wasn't erroring it was returning a blank cell because the cell was empty in the previous sheet.

    After some googling around I found the isEmpty function. So Combined with that and the code provided I tweaked it so it is:

    Please Login or Register  to view this content.
    So now it works perfectly. Thank you for all your help.

    James

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Multiplying by 100 each cell in input range
    By lucazzo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2017, 12:51 PM
  2. Adding date on input in cell
    By Megashira in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-07-2014, 01:54 AM
  3. [SOLVED] Adding X Columns for user input based on value of one cell
    By reluctantresearch in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-25-2013, 01:50 PM
  4. [SOLVED] Adding color to a cell based on input value
    By cadamhill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2012, 10:15 AM
  5. Adding a Calendar for quick cell input
    By ImagineParidise in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-15-2012, 03:23 AM
  6. Copy & paste with input box, adding a blank cell
    By Flower R in forum Excel General
    Replies: 5
    Last Post: 11-01-2009, 12:58 PM
  7. Problem adding input to cell
    By PghPatti in forum Excel General
    Replies: 6
    Last Post: 06-30-2005, 08:05 AM

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