+ Reply to Thread
Results 1 to 2 of 2

Adding OR statement into If statement

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-03-2009
    Location
    UK
    MS-Off Ver
    MS365 Subscription Excel for Mac
    Posts
    1,017

    Adding OR statement into If statement

    I have the below which works fine@

    Dim rng As Range, Wrd As String, wa As Boolean, wb As Boolean
    Dim ws2 As Worksheet: Set ws2 = Worksheets("Sheet2")
    Dim ws3 As Worksheet: Set ws3 = Worksheets("Sheet3")
    
    For Each rng In ws2.Range("B2:B" & ws2.Range("B" & Rows.Count).End(xlUp).Row)
                 
                Wrd = rng.Offset(0, 2)
        If rng = "Test" Then
                            If wa = False Then
            If Wrd = ws2.Range("C1").Value Then
                rng.Offset(0, -1).Copy ws3.Cells(3, "AJ")
                wa = True
                    End If: End If
                                If wb = False Then
                        If Wrd = ws2.Range("D1").Value Then
                           rng.Offset(0, -1).Copy ws3.Cells(3, "AK")
                           wb = True
                        End If: End If
                 
                End If
    Next rng
    However, if I want to add another word in such as Excel then how do I add an Or? Is it:

    Dim rng As Range, Wrd As String, wa As Boolean, wb As Boolean
    Dim ws2 As Worksheet: Set ws2 = Worksheets("Sheet2")
    Dim ws3 As Worksheet: Set ws3 = Worksheets("Sheet3")
    
    For Each rng In ws2.Range("B2:B" & ws2.Range("B" & Rows.Count).End(xlUp).Row)
                 
                Wrd = rng.Offset(0, 2)
        If rng = "Test" Or "Excel" Then
                            If wa = False Then
            If Wrd = ws2.Range("C1").Value Then
                rng.Offset(0, -1).Copy ws3.Cells(3, "AJ")
                wa = True
                    End If: End If
                                If wb = False Then
                        If Wrd = ws2.Range("D1").Value Then
                           rng.Offset(0, -1).Copy ws3.Cells(3, "AK")
                           wb = True
                        End If: End If
                 
                End If
    Next rng
    If I do this it doesn't work though!

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,944

    Re: Adding OR statement into If statement

     If rng = "Test" Or rng = "Excel" Then
    BSB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding CountIf Statement within If/ElseIf Statement
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2014, 05:09 AM
  2. Help adding an IF statement?
    By jawnmallon in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-24-2013, 09:13 PM
  3. Adding an if statement to vba
    By Nicola13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2012, 06:48 AM
  4. Adding an OR statement for a value
    By garopro in forum Excel General
    Replies: 4
    Last Post: 12-07-2011, 05:30 PM
  5. Adding an OR statement
    By Ang12345 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2010, 01:54 PM
  6. IF Statement + adding
    By burblecut in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-02-2008, 11:50 AM
  7. Adding in a ADD statement
    By Algeraist in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-17-2008, 03:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1