QUICK Question to alter IF statement in Macro

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
Hi All:

Below is the beginning portion of my code and I want to alter it to say:

IF cell "B5" of the "Input Sheet" equals 7 or 27 or 37 then continue with the code otherwise EXIT SUB.

I ahve played around a bit but can't get it to function... THANKS.
Code:
Sub MiscReconSort()
''''''''''''''''''''''''''''
Sheets("MiscRecon").Select
Range("A5").Select



If Sheets("Input Sheet").Range("B5").Value = "7","14","37" Then



If Sheets("MiscRecon").Range("C256").Value = 0 Then Exit Sub

ActiveSheet.Unprotect "unlock"

How do I change this line to reflect my wishes??? :biggrin: THANKS.
Code:
If Sheets("Input Sheet").Range("B5").Value = "7","14","37" Then

Take Care,
Mark :)
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Mark

Why not use a Select Case structure instead?
Code:
Select Case Sheets("Input Sheet").Range("B5")

     Case 7, 14, 37
            ' continue with code
     Case Else
            Exit Sub
End Select
 
Upvote 0
Hi Norie:

THANKS for the suggestion. Do I just add your portion to my code? Like:

Code:
Sub MiscReconSort() 
'''''''''''''''''''''''''''' 
Select Case Sheets("Input Sheet").Range("B5") 

     Case 7, 14, 37 
            ' continue with code 
     Case Else 
            Exit Sub 
End Select


'My code goes below???  
Sheets("MiscRecon").Select 
Range("A5").Select 
If Sheets("MiscRecon").Range("C256").Value = 0 Then Exit Sub 

ActiveSheet.Unprotect "unlock"

I am heading home shortly but I will experiment with your suggestion when I return to the office.

THANKS again Norie :biggrin:

Have an EXCELLENT weekend,
Mark :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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