• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Comparing two cells values in Switch case in macros|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Comparing two cells values in Switch case in macros|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosComparing two cells values in Switc…
sp_PrintTopic sp_TopicIcon
Comparing two cells values in Switch case in macros
Avatar
Soumya Jena

New Member
Members
Level 0
Forum Posts: 2
Member Since:
March 8, 2019
sp_UserOfflineSmall Offline
1
March 8, 2019 - 4:22 pm
sp_Permalink sp_Print

Hi,

As I am a beginner to macros, I have some basic doubt in using switch case.

I am trying to use multiple condition in switch case which uses two column reference value.

For eg. in the below table, there are some common roles in both project A and B. Based on the project I need to set the rate for common roles in column 3. Say for example SIT manager is common to project A and B but the rate for them is different.

I tried using IF condition and it worked fine. Now I need to make it more efficient using Select Case. Please provide me any solution how to achieve it.

 

Project Roles Rate
A Defect manager  
B SIT manager 100
A SIT manager 150
A UAT manager  
B NFT manager 320
B Automation Engineer  
A NFT manager 350

 

Sample code for Switch case:

Sub CaseTrial()

Dim role As Range
Dim Rate As Long

Set role = Range("D2:D200")

Range("D2").Select

Select Case role

Case (Selection.Offset(0, 0) = "SIT manager" And Selection.Offset(-1, 0) = "A")

Cells(4, 3).Value = 150

Case Else

Cells(4, 3).Value = 0
'rate = 100

End Select

End Sub

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
2
March 8, 2019 - 5:02 pm
sp_Permalink sp_Print

Hi,

Please provide a workbook rather than typing data and code so we don't have to recreate everything.

You can do what you want with a combination of VLOOKUP and IF, you don't need VBA.

Please see attached workbook.

You haven't provided values for all the rates so just fill those in on the worksheet and everything should work.

Please read this explanation of how to use VLOOKUP

Regards

Phil

Avatar
Soumya Jena

New Member
Members
Level 0
Forum Posts: 2
Member Since:
March 8, 2019
sp_UserOfflineSmall Offline
3
March 8, 2019 - 6:37 pm
sp_Permalink sp_Print

Hi,

Actually I need to automate the sheet so that no.of resources under one role will be updated easily. I know we can use VLOOKUP in EXCEL but I want to now how we can use macros using Switch case for the same.

Hereby attaching the sheet for your reference.

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1514
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
March 8, 2019 - 8:04 pm
sp_Permalink sp_Print

Hi,

This is why supplying the actual workbook and thoroughly explaining the expected result is so important.  The work I did in my first answer was wasted time.

I still don't really understand what you want to do and the sample workbook doesn't look like the actual workbook you will use.  I need to work with an accurate copy of the real workbook, with at least a subset of the data.  The layout of the sample is not the layout of the real workbook so anything I write will need to be altered to fit the real situation.

What do you mean by 'need to automate the sheet'?  Why?  For what purpose?  How/where do you intend to update the number of resources under one role? What is a resource?  It's not mentioned in the workbook.  How does a resource relate to a role?

I need to understand what you mean by this and see an example properly laid out in the sheet.

Phil

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Lynnette Altomari, Sherry Fox, Riny van Eekelen, Dieneba NDIAYE, Tucker Oakley
Guest(s) 12
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Sopi Yuniarti
sandra parker
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Forum Stats:
Groups: 3
Forums: 24
Topics: 6214
Posts: 27243

 

Member Stats:
Guest Posters: 49
Members: 31894
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.