Solved

Excel VB - Case statement - 2 variables

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

760 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

22 Experts available now in Live!

Get 1:1 Help Now