Solved

Excel VB - Case statement - 2 variables

Posted on 2011-02-23
4
527 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 142

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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

943 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

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now