You are here:

# Excel/User Form in Excel

Advertisement

Question
Hello Damon,

I am working on a spreadsheet in excel that lists 4 compounds, there molecular weights, k-values, Peak Areas, Mole and Mass Fractions. There are 5 samples of these for compounds. The k-values are constant throughout. The Peak Areas are different for each compound and each sample. I have written a VBA code to calculate the Mole and Mass Fraction. Everything is correct in the array boxes.

Sample   MW   k-Values   Peak Areas   Mole Frac.  Mass Frac.
1    16.04   0.150        3.6          0.156      0.062
30.07   0.287        2.8          0.233      0.173
44.09   0.467        2.4          0.324      0.353
58.12   0.583        1.7          0.287      0.412
2     --      --          --          --         --
and so on through sample 5.

I have been asked to construct a user form to return the mole and mass fractions as well.  The user will enter the k-values, number of compounds, number of samples, and peak areas. The Moles and Mass Fractions are to be displayed on the worksheet and not the user form. I am not real sure how to write the code for this.

The information for this project is suppose to be values that are collected from a gas chromatograph.

For this example the moles for each compound = k * Peak Area.
The Mole Fraction = moles(i) / total moles in each sample.
The Mass Fraction = Mass(i) / total Mass in each sample.

Can you please help?

Also I am a beginner to VBA and UDF codes.

Thank you for your time!

Sincerely,

Stephen Meiring

Answer
Hi Stephen,

Firstly I want to apologize for my slow response.  I saw your question last week but didn't have time then to do it, and I forgot that I had a question pending until I got notification from AllExperts that it was overdue.

It would take quite a bit of explanation to give all the steps in setting up such a userform and I think that showing you such a userform and its associated code would be much easier. Here is my email address: VBAexpert@myway.com.  If you email me I will send you back an example userform that does basically what you describe.  Even better, if you could send me your Excel worksheet with the sample 1-5 data sets I could add the userform and code to your workbook and email it back to you.

Damon
Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Damon was very helpful.

• Add to this Answer
• Ask a Question
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

#### Damon Ostrander

##### Expertise

I have extensive experience with VBA programming in Excel 5 through Excel 2013. As a former aerospace engineer with a large aerospace corporation and consultant in a small defense technology services company, I have developed a wide range of applications in VBA, including simulations involving mixed-language programming, satellite orbit mechanics, graphics and animation, and real-time applications. I am interested in moderate to hard VBA-related questions only.

##### Experience

I have developed and taught several courses in Excel VBA programming and also VBA programming in Office 97, 2000, and 2007. I have developed a number of large technical applications in Excel VBA for use within the aerospace industry.

Education/Credentials
B.S. in Electrical Engineering and Computer Science, University of California, Berkeley.

©2016 About.com. All rights reserved.

Browse Answers: