+ Reply to Thread
Results 1 to 2 of 2

Help with If not-statement

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    Gothenburg, Sweden
    MS-Off Ver
    Excel 2007/Excel 2010
    Posts
    14

    Help with If not-statement

    Hi,

    I'm writing a macro at work to help a few colleagues (and, occasionally, myself) out. The main function of the program works flawlessly, yet one thing still bothers me.

    After that I've declared all my variables I want the macro to check if the rows A:A and B:B are empty, and if they are not, to display a message which says that the macro will replace all current information in the A:A and B:B cells and ask whether the user wants to call the macro or not. The problem is that the message declaring that the cell values in A:A and B:B will be replaced pops up even if the cells are seemingly empty.

    I've tried to rewrite the code in a couple of different ways. Here's current version of the code that's annoying me:
    Dim blablabla
    [...]
    Empty1 = IsEmpty(Range("A:A"))
    Empty2 = IsEmpty(Range("B:B"))
    If Not Empty1 = True Or Empty = True Then
    Assert = "All information in the columns A and B will be replaced." & vbNewLine & vbNewLine
    Assert = Assert & "Do you still want to continue?"
    Ans1 = MsgBox(Assert, vbYesNo)
    If Ans1 = vbNo Then Exit Sub
    End If

    Range("A:A").Clear
    Range("B:B").Clear

    [...]
    Does anyone have any ideas on how to solve this and where I might have lost my way?

    Cheers,

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Help with If not-statement

    Change this line to this.

    If Empty1 = True Or Empty = True Then
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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