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 :)
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
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
 

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
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:
 

Watch MrExcel Video

Forum statistics

Threads
1,122,804
Messages
5,598,140
Members
414,214
Latest member
marketingnumbersguy

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
Top