+ Reply to Thread
Results 1 to 3 of 3

Empty and Non Empty Visual Basic

  1. #1
    Registered User
    Join Date
    03-22-2005
    Posts
    31

    Empty and Non Empty Visual Basic

    Hi Everyone.
    I've been trying to incorporate some extra commands into my VB Codes.
    I want my spreadsheet to see B4 is empty, and if it is, select b4 once again and clear contents. I want it to see if it's not empty (so if it has number 3 or 32...) and then copy B4 to Z2, then copy z3 to b4

    If Range("b4") = Empty Then
    Range("b4").Select
    Selection.ClearContents
    End If
    If Range("b4") = Not Empty Then
    Range("b4").Select
    Selection.Copy
    Range("Z2").Select
    ActiveSheet.Paste
    Range("Z3").Select
    Selection.Copy
    Range("b4").Select
    ActiveSheet.Paste
    End If

    It doesn't seem to be working, so obviously I'm doing something wrong. Would anybody be able to help me out. Im not even sure if I should be using "Not Empty"
    Thanks Guys,

    Andrew

  2. #2
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Following your brief (curious in part), try:

    Sub ChkEmpt()
    If Isempty(Range("b4")) Then
    Range("b4").ClearContents
    End If

    If Not Isempty(Range("b4")) Then
    Range("b4").Copy Range("Z2")
    Range("Z3").Copy Range("b4")
    End If
    End sub

    By the way, why would you like to clear contents of an empty cell? The bolded lines can just as well be deleted

  3. #3
    Registered User
    Join Date
    03-22-2005
    Posts
    31
    Thanks Davidm.
    Firstly, this worked perfectly, thankyou very much, and secondly in relation to your question about clearing an empty cell, it's because I use an advanced filter with 3 different criteria, Lot number, street number, and street name and for some reason It causes some problems with a cell that hasn't been cleared properly and this seems to remedy the problem. I don't know why or how come, but it does.
    Thanks David

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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