473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Excel VBA basics

I'm attempting to write a simple VBA procedure to do pressure unit conversions. Basically, I want to be able to convert from one of several units of measure to another one of several units of measure. The script needs to examine the value entered by the user as well as the "from" unit...and based on that unit selected from a dropdown list, go to a subroutine to compute the "to" value (like "from" n.nnn millibars "to" n.nnn inches of mercury).

I need to know two very basic things:

1. How do I get the values from my cell into the script from the worksheet, and how do I get the computed values out of the script back into the worksheet?
2. How do I use an IF THEN ELSE statement to send the script to the right sub procedure to do the computation? (I'm getting an "undefined label" error message.)

Anyone's help is much appreciated.
Jan 4 '07 #1
4 2851
Killer42
8,435 Expert 8TB
I'm attempting to write a simple VBA procedure to do pressure unit conversions. Basically, I want to be able to convert from one of several units of measure to another one of several units of measure. The script needs to examine the value entered by the user as well as the "from" unit...and based on that unit selected from a dropdown list, go to a subroutine to compute the "to" value (like "from" n.nnn millibars "to" n.nnn inches of mercury).

I need to know two very basic things:

1. How do I get the values from my cell into the script from the worksheet, and how do I get the computed values out of the script back into the worksheet?
2. How do I use an IF THEN ELSE statement to send the script to the right sub procedure to do the computation? (I'm getting an "undefined label" error message.)

Anyone's help is much appreciated.
Could you show us the code you have written so far?

I'm not expert in the Excel/VBA area, but I believe you can reference a cell by simply using (for example) Range("A1").Value. You can set values the same way.

IF/THEN/ELSE is pretty straightforward and simple to use - I think we need to see what you have, to be able to help with this.
Jan 4 '07 #2
Hi,

I've been writing Excel VBA scripts for a couple of years now so hopefully I can help!

A better way than calling the value directly from a cell is to put it into a variable, this will make your code writing easier to read and understand. You can also change the cell which contains the value to be converted without having to change your code multiple times.

Also depending on the number of different conversions you want to do you may want to use a Select Case statement. They are a little tidier than IF...THEN...ELSE statements.

As Killer42 said if you post your code I'll take a look.
Jan 7 '08 #3
Don't bother. Get Uconeer software. It has conversion factors for everything! And if you still want to code your own, It is a good format to follow.

Bobby
Jan 7 '08 #4
Killer42
8,435 Expert 8TB
Thanks for the suggestions people, but given that it's over a year now, it might be a bit late. :)

Caterism, I suspect using a variable rather than a cell reference would also improve execution speed slightly, but don't know for sure.
Jan 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to...
0
by: Shawn | last post by:
I have the basics working as is described in KB199841. I currently have my ASP page loading into Excel by setting the ContentType of the page: <%response.ContentType="application/vnd.ms-excel"%> ...
2
by: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get...
1
by: Robin Tucker | last post by:
Heres and interesting problem: I have a VB.NET program that creates reports via. Word Automation. This all works fine. What I want to do as part of this report generation process is to embed a...
3
by: kenduron | last post by:
Hello together, I simply want to export table data to a new excel file without saving this file to local hard disk drive, the user should decide where to store. Alltogether, the excel sheet...
10
by: Steve | last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains custom functions. I believe I need to use COM interop to allow VBA code in Excel 2002 to access it. I've studied...
1
by: madhu sudhan | last post by:
HI, I want to read data from excel file and export this data to dataset. I know abt the basics of opening a file using application, workbook and worksheet classes. But i don't know how to read...
2
by: rene.marxis | last post by:
Hi I need some hints for the following problem. We have some customer that has one Excel file composed of about 20 sheets and he wants to convert this file to a small C# application. It's not...
2
by: news.microsoft.com | last post by:
Not sure the best group to post to, so sorry for the cross post :(. There are several posts out there of how to automate excel from .net, i.e in the sample below, they are using Excel 9.0......
7
by: CSharpCoder | last post by:
I have an Excel VBA app that has 25 forms within and is reading from 60 Excel Sheets for a datasource. This needs to be converted over to the web in 10 days, and it took almost 3 months to do the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.