+ Reply to Thread
Results 1 to 8 of 8

Problem with If Or statement.

  1. #1
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Problem with If Or statement.

    Hi Guys,

    I am trying to use an If Or statement but seem to be having a problem.

    There could be a filenamed TEST or it could be Test.

    I need a message box to tell the user if the ActiveWorkbook.Name is NOT TEST or Test

    This works if the file is named Test.xlsm.
    Please Login or Register  to view this content.
    This works if the file is called TEST.xlsm.
    Please Login or Register  to view this content.
    This does NOT work, always shows the message box, even if the active workbook is either of the filenames.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Problem with If Or statement.

    How about:

    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Problem with If Or statement.

    Try:
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Problem with If Or statement.

    I have just tested the AND instead of the OR and it works great, thanks Akuini.

  5. #5
    Forum Contributor banaanas's Avatar
    Join Date
    08-26-2014
    Location
    Finland
    MS-Off Ver
    2016
    Posts
    199

    Re: Problem with If Or statement.

    Personally I find that a good practice always when you do string comparisons is to use (ucase(trim("String here")) = (ucase(trim("String2 Here")) to trim excess spaces and make it uppercase when doing comparisons.
    As KOKOSEK already posted
    Tuomas "Banaanas" Savonius
    Trying to give back now when I actually can do some VBA

  6. #6
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Problem with If Or statement.

    I tried (UCase(ActiveWorkbook.Name) <> "TEST") and (UCase(ActiveWorkbook.Name) <> "Test") just in case, but both failed.

    I replaced the OR with AND as suggested by Akuini, the AND worked great.

    Thanks for trying Kokosek.

  7. #7
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,742

    Re: Problem with If Or statement.

    Does not make sense because Ucase("test") = Ucase("TEST") so there is no need to check twice with AND.
    Why on my excel in ActiveWorkbook.Name I got only Book1 without .xlsm?

    p.s. I am dumb. On fresh sheet before 1st save, there is no extension yet.

    Anyhow:
    Lower case sort this out in one check:
    Please Login or Register  to view this content.
    Last edited by KOKOSEK; 02-06-2019 at 08:18 AM.

  8. #8
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Problem with If Or statement.

    I don't know, when stepping through my code, I have inserted Debug.Print this shows the full name including the .xlsm as does MsgBox ActiveWorkbook.Name

+ 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. [SOLVED] If statement Problem
    By excobra in forum Excel General
    Replies: 6
    Last Post: 08-24-2016, 06:09 AM
  2. [SOLVED] If - Then - Else Statement Problem: Next without For
    By brgr4u in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-20-2013, 02:04 PM
  3. [SOLVED] IF Statement PROBLEM
    By Umar in forum Excel General
    Replies: 2
    Last Post: 06-14-2012, 07:20 AM
  4. Now() statement within a IF(AND statement problem
    By Modify_inc in forum Excel General
    Replies: 3
    Last Post: 03-27-2011, 04:17 PM
  5. Problem with IF statement within a COUNTIF statement
    By girlofscience in forum Excel General
    Replies: 5
    Last Post: 04-22-2009, 10:20 AM
  6. IF Statement Problem
    By RagDyer in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-06-2005, 06:05 AM
  7. Re: If Statement Problem
    By Robert Hargreaves in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2005, 09:05 PM

Tags for this Thread

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