Solved

if else statement to select values from workbook

Posted on 2013-12-28
2
348 Views
Last Modified: 2013-12-28
folks I have a function which activates a select from a specific workbook

Function Select Region()

' Activating GenericUser sheet
ActiveWorkbook.Sheets("Region1").Activate

however I would like to change the sheet to be used based on the region as specified in sheet 1 i.e.

if sheet1 b1 = europe then

ActiveWorkbook.Sheets("Region1").Activate


else if sheet1 b1 = asia then

ActiveWorkbook.Sheets("Region2").Activate

else if sheet1 b1 = africa then

ActiveWorkbook.Sheets("Region3").Activate

how do i correctly program this?
0
Comment
Question by:rutgermons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 39743589
Sub Select_Region()
  select [Sheet1!B1]
    case "europe": rg = "Region1"
    case "asia": rg = "Region2"
    case "africa": rg = "Region3"
    case else: rg = "Region4"
  End select
  ActiveWorkBook.Sheets(rg).Activate
End Sub

Open in new window

0
 
LVL 13

Accepted Solution

by:
Ashok earned 500 total points
ID: 39743604
Function Select_Region()
   If Sheet1.Range("B1") = "europe" Then
     ActiveWorkbook.Sheets("Region1").Activate
   ElseIf Sheet1.Range("B1") = "asia" Then
     ActiveWorkbook.Sheets("Region2").Activate
   ElseIf Sheet1.Range("B1") = "africa" Then
     ActiveWorkbook.Sheets("Region3").Activate
   End If
End Function
Test-Function.xlsx
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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 …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

696 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