+ Reply to Thread
Results 1 to 5 of 5

[VBA] unit conversion using drop down list

  1. #1
    Registered User
    Join Date
    04-22-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    14

    Smile [VBA] unit conversion using drop down list

    Hi everyone,

    This is my first post in this forum and nice to meet you all here.

    I am a new learner of vba, so I still have a lot of technical stuff that I am not yet familiar with and you can think of me as a beginner.

    The problem that I have with my database or I am trying to solve is that:


    Background
    - I have a table which contains some data lets say 2 by 2 for the sake of simplicity
    - I would like to create a drop down list which contains different units for distance/lengths for example, meters, inches, and the original data table is in meters as a default
    - when the user select an option from the drop down list, let's say inches, all the data on the table will convert into inches from meters.

    A general overview
    Input (one): an option from the drop down list
    Process: all the data on the table times a constant value which depends on the input
    Output (many): all the data on the table will be converted into different values that correspond to the input

    My thoughts
    I know there are always different methods to go about it, however, I would like to have a process that involves automatic calculation, for example, the developer only requires to have another worksheetwhich stores all the conversion units which will be used by excel to process the data, rather than having many different result tables for each unit which is manually obtained by timing each data with the constant.

    I am not sure whether I have explained it clearly, feel free to ask any questions or provide suggestions that would achieve the same result.

    Thanks a lot!

    Frank

  2. #2
    Registered User
    Join Date
    04-07-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    34

    Re: [VBA] unit conversion using drop down list

    Please attach a sample file, will try to get an idea for the VBA

  3. #3
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: [VBA] unit conversion using drop down list

    Easiest to do with 2 grids. The first contains the data in a known unit of measurement, the 2nd contains the converted values.

    But it can be done with 1 grid, the only complication is that everything must be converted back to a default measurement system before converting again to the desired system.

    For example - Add some numbers to G5:I7 (Totally arbitrary, it's just what I highlighted). To help validate the results make these simple units (1, 2, 3...), Add a Data Validation list to F3, I used 'Inches,Feet,Yards, MM, CM, M'. Inches are my 'standard', the factors below will have to change if that changes.

    Add the following code to the worksheet code module
    Please Login or Register  to view this content.
    It's not the best code, but illustrates the idea. Also it may introduce rounding errors but I don't think you'll need that sort of precision. You can always format the cells with as many decimal places as needed as remove the Rounding in the code. Also, you cannot edit the values unless the 'standard' unit of measurement is selected.

    If you decide to use 2 grids then it's a simple matter of looping through the 'static' grid calculating the new values in the second using whatever factor for the selection. No need for 2 passes.
    Last edited by cytop; 04-24-2016 at 08:06 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    05-08-2015
    Location
    Uvalde, TX
    MS-Off Ver
    2010
    Posts
    720

    Re: [VBA] unit conversion using drop down list

    Hi Frank,

    Give the attached file a try.

    Hope it helps
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-22-2016
    Location
    London
    MS-Off Ver
    2013
    Posts
    14

    Re: [VBA] unit conversion using drop down list

    Thank you for all the replies, you guys have solved my problem, thank you!

+ 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. Unit conversion button
    By jeffking30 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-18-2015, 11:59 AM
  2. Unit Conversion
    By mcphatty in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-21-2013, 02:29 PM
  3. Unit conversion
    By hollanu in forum Excel General
    Replies: 10
    Last Post: 10-10-2012, 03:36 PM
  4. Conditional Unit Conversion Macro
    By Lavistyksia in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-20-2011, 02:32 PM
  5. Unit Conversion
    By j.mayo11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2010, 03:21 PM
  6. Spreadsheet with Unit Conversion Factors
    By DM2 in forum Excel General
    Replies: 3
    Last Post: 12-20-2009, 04:36 PM
  7. Excel Unit Conversion
    By cs4 in forum Excel General
    Replies: 2
    Last Post: 03-18-2009, 05:07 PM

Tags for this Thread

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