Select Case - only if match found

SuperFerret

Well-known Member
Joined
Mar 2, 2009
Messages
515
I'm trying to get my head around Select Case statements, I've searched online but I haven't been able to find anything that will help my understand the syntax :-(

I need to understand how to say:
IF Sheet1 A1 = Sheet2 A1 then do something
IF Sheet1 B1 = Sheet2 B1 then do something

But I want to be able to understand it, I thought I'd got it but my brain has failed me!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I'm not sure you need Select Case. Simple IF's should do!!
Code:
If Sheet1.Range("A1")  = Sheet2.Range("A1") Then
     Do something
ElseIf Sheet1.Range("B1") = Sheet2.Range("B1") Then
     Do something
End If
lenze
 
Upvote 0
Thanks lenze, that actually seems remarkably simple!

I know in the near future I'm going to need to build some big macro's and I want to try and get my head around the basics of Select Case statements before I actually need to use them! I'll keep searching but using IF's should do me for now! :biggrin:
 
Upvote 0
So with this can I keep going?

Is there a limit on the number of IF's before I need to move onto something else?
 
Upvote 0
Select Case is not really difficult once you get the hang of it. I actually prefer it in most cases. For your example, which uses logical tests, it is probably better to use the IFs. Don't really know without seeing your macro. A Google search for "Select Case in Excel" should give you ample articles to peruse!!

lenze
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top