+ Reply to Thread
Results 1 to 5 of 5

VBA to convert cell value based on drop down selection (part 2)

  1. #1
    Registered User
    Join Date
    03-01-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    78

    VBA to convert cell value based on drop down selection (part 2)

    Hi

    Managed to get my queries answered and code to work with guru's help here.
    But after testing it out, it does not work smoothly according to plan.

    Attached is a sample workbook to illustrate.

    Column A is for the user to key in a "Value", and Column B is a drop-down list ("sqft", "sqm"), for the user to indicate the unit of the "Value" in column A.
    The code works so far in converting the "Value" from "sqft" to "sqm" and back.

    The problems
    • When user keyed in the "Value" in column A, then select the unit from the drop-down list. What the code does is to multiply/ divide the "Value" with 10.76. Hence, the "Value" will be incorrect.

    Example: If i keyed in 5000 into Column A1 followed by selecting "sqft" from the drop-down list. The final value in Column A1 will be 53819.55 which is wrong


    • When user select the unit (e.g. sqft) more than once from the drop-down list. The code will again keep multiplying/ dividing the "Value" with 10.76.

    Example: If i keyed in 5000 into Column A1 and select sqft from the drop-down list twice. The final value in Column A1 will be 579308.84 which is incorrect. Its should remain as 5000.


    • If i were to delete a row (e.g. Row 2), it will give me a Run-time error "13": Type mismatch


    Need help from gurus here to rectify these areas.

    All help appreciated


    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: VBA to convert cell value based on drop down selection (part 2)

    Which version you are using? Excel 2003? If not, please update your profile to reflect the correct excel version you are using.

    Replace the existing code on Sheet Module with the following codes and see if your issues get resolved.


    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    03-01-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    78

    Re: VBA to convert cell value based on drop down selection (part 2)

    Thanks again sktneer!

    Yes it works in general except point 1.
    I.e. If user wants to input the value - 1000 sqft. User keyed 1000 into Cell A1 then select "sqft" from the srop-down list (which is initially "blank"). the answer will be incorrect. Similarly, if user wants to input 500 sqm, the code takes it and divide by 10.76 when "sqm" is selected from the drop-down list.


    When user keyed in the "Value" in column A, then select the unit from the drop-down list. What the code does is to multiply/ divide the "Value" with 10.76. Hence, the "Value" will be incorrect.

    Example: If i keyed in 5000 into Column A1 followed by selecting "sqft" from the drop-down list. The final value in Column A1 will be 53819.55 which is wrong
    Appreciate your time and help rendered.

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: VBA to convert cell value based on drop down selection (part 2)

    You spoke about the wrong value but didn't speak about the expected correct value.

    Anyways, try this and let me know if you are getting the desired output now...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sktneer; 03-10-2018 at 02:28 AM.

  5. #5
    Registered User
    Join Date
    03-01-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    78

    Re: VBA to convert cell value based on drop down selection (part 2)

    Let me try it out and revert.

    Thanks!

+ 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] VBA to convert cell value based on drop down selection
    By whoosh in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-08-2018, 08:04 AM
  2. Autofill a cell based on selection in drop down menu
    By fyrfytr265 in forum Excel General
    Replies: 4
    Last Post: 01-30-2014, 10:35 AM
  3. Populating a cell based on drop down selection
    By cronerd in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-25-2013, 11:07 AM
  4. [SOLVED] Change color of cell based on drop down selection
    By madhatter40 in forum Excel General
    Replies: 3
    Last Post: 12-14-2012, 07:27 PM
  5. Autofill cell based on drop-down selection
    By littlebird6180 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-06-2012, 03:09 PM
  6. Hiding rows based on drop down selection of cell
    By J-Fly in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2012, 01:37 PM
  7. change cell values based on drop down box selection
    By Aniruddha in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2006, 05:30 PM

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