Solved

Excel VB - Case statement - 2 variables

Posted on 2011-02-23
4
550 Views
Last Modified: 2012-05-11
Hi there

I am trying to implement a CASE statement in VB with 2 variables.

I have attached a spreadsheet of how i want this to work.

There are basically 2 columns with UoM1 and UoM2.

The code needs to run down each row and check what's in UoM1 and UoM2.

Column E shows the calculations to do when it meets those conditions.

((I know conversions are not correct - this is just an example!))

How do i express this in VB code to run in excel?

Many thanks
Irfan convert-Case.xls
0
Comment
Question by:irfanibrahim
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34959928
in vba or as cell function?
0
 

Author Comment

by:irfanibrahim
ID: 34963283
in vba - i know i could use an formula  but there are going to be a lot more conditions
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34963409
you could do something like this:

r = 0.01
UoM1 = "MM"
UoM2 = "M"
select case UoM1 & "-" & UoM2
  case "MM-M"
     r = r * 100
  case "M-M"
     r = r * 1000
   case "EA-EA"
     r =  r
   case "M-MM"
     r = r / 100
end select

Open in new window

0
 

Author Closing Comment

by:irfanibrahim
ID: 34994490
hi there
i manged to get it working - the end result is a bit different to the example you gave but it did help me work it out
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running Access application from Task Scheduler 6 68
Creating An Intelligent Dropdown 8 48
Adding a countdown to HTA 12 99
Hta File displays dynamic File names 4 49
This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question