IF THEN ELSE (vba)

gtd526

Well-known Member
Joined
Jul 30, 2013
Messages
657
Office Version
  1. 2019
Platform
  1. Windows
Hello,
If rng = playoff,div,champ,sb then dont perform anything
if rng = 1 thru 17 then perform bottom half
thank you.

VBA Code:
Sub test()

Dim rng As Range

Set rng = Worksheets("Weekly Picks").Range("B1")
'MsgBox rng
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'works, is there a shorter code?
'update My ATS Avg using week #(B1), copy/paste
    If rng = "Playoff" Or _
       rng = "DIV" Or _
       rng = "Champ" Or _
       rng = "SB" Then
    Else
    End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'dosent work!
'    If rng = "Playoff" Or "DIV" Or "Champ" Or "SB" Then
'    MsgBox rng
'    Else
'    End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''bottom half
'dont want to perform if above is true, perform iif rng = 1 thru 17??
'PDate is a Week #
    PDate = Worksheets("Weekly Picks").Range("B1")
    Worksheets("My ATS Avg").Select
    Set foundRng = Rows(2).Find(PDate)
        foundRng.Select
        ActiveCell.Offset(1, 0).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Selection.PasteSpecial xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
  
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

use below code:

VBA Code:
Sub test()
    Dim rng As Range
    Set rng = Worksheets("Weekly Picks").Range("B1")
    If rng >= 1 And rng <= 17 Then
            MsgBox rng
    End If
End Sub
 
Upvote 0
Solution
Do you mean you want
VBA Code:
If rng = "Playoff" Or rng = "DIV" Or rng = "Champ" Or rng = "SB" Then Exit Sub
 
Upvote 0
Hi,

use below code:

VBA Code:
Sub test()
    Dim rng As Range
    Set rng = Worksheets("Weekly Picks").Range("B1")
    If rng >= 1 And rng <= 17 Then
            MsgBox rng
    End If
End Sub
Thank you for the reply.
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

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