+ Reply to Thread
Results 1 to 7 of 7

If statement not working....

  1. #1
    Registered User
    Join Date
    02-18-2015
    Location
    Norwich
    MS-Off Ver
    13
    Posts
    4

    If statement not working....

    Please help....

    I'm trying to get my IF statement to 'Exit' at this line if there is nothing in the variable strFile.

    This is the line of code -
    Please Login or Register  to view this content.
    But the program just ignores it and carries on through. What am I doing wrong?
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 07-14-2015 at 08:50 AM.

  2. #2
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: If statement not working....

    Please put the code in code tags.
    I would guess that the function wksexists throws an error cause the worksheet does not exists. Cause you have on error resume next nothing happens. Before at the beginning of you function set the function to false then it should work

    Sent from my GT-I9505 using Tapatalk

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,748

    Re: If statement not working....

    Move your End If as shown. (Other solutions are possible.)
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    02-18-2015
    Location
    Norwich
    MS-Off Ver
    13
    Posts
    4

    Re: If statement not working....

    Thanks - tried moving the end if but no luck. This line //strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv")// opens Windows explorer so that the user can choose a file. In the event that someone chooses not to select a file but instead clicks CANCEL from the file dialogue box they get a debug error - presumably because strFile is blank. Hence If strFile <> "" Then End If

    How do I put my code in quotes by the way? Are we talking about ""? Relative newbiee...

  5. #5
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: If statement not working....

    Did not work cause strfile becomes False when you click Cancel not ""

    This should work

    Please Login or Register  to view this content.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,748

    Re: If statement not working....

    Quote Originally Posted by bear77 View Post
    How do I put my code in quotes by the way? Are we talking about ""? Relative newbiee...
    No--tags, not quotes.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    You can type in the tags, or highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  7. #7
    Registered User
    Join Date
    02-18-2015
    Location
    Norwich
    MS-Off Ver
    13
    Posts
    4

    Re: If statement not working....

    Many thanks to all who responded. I've sussed it now - needed to change the strFile type from string to variant and then use <> 0 to check for its existence!

+ 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] cant get if statement working
    By Ditch1983 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 03-23-2015, 05:20 PM
  2. [SOLVED] IF statement not working.
    By OwlChutney in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2014, 01:51 PM
  3. Working While Statement Stops Working
    By Verbaruab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2011, 05:58 PM
  4. If statement not working
    By lit2003 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2008, 09:33 AM
  5. My If statement not working
    By rlkerr in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-04-2007, 12:42 PM
  6. #N/A not working in IF statement
    By Turnipboy in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-24-2007, 05:03 AM
  7. If statement not working right
    By TimT in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2005, 02:05 PM

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