Solved

"" not treated as empty

Posted on 2011-09-04
3
292 Views
Last Modified: 2012-06-27
The below code works as long as the file is emptied by using the Delete Key..  If I go in and hit the spacebar to empty it ignores the value = "".  

So for example hte

  If .Offset(0, -1).Value = "" Then

can appear empty, but the script does not treat it as such.

Sub CheckData()
Dim i As Long
Dim blFailed As Boolean
Dim col As Long
col = 19  '34 to 40 are good
col2 = 3

ActiveSheet.Activate
ActiveSheet.Unprotect

For i = 12 To 50
    With ActiveSheet.Cells(i, "F")
        If .Value = "MAX" Then
           If .Offset(0, -1).Value = "" Then
                 blFailed = True
                 .Offset(0, -1).Interior.ColorIndex = col2
             Else
                 .Offset(0, -1).Interior.ColorIndex = col
             End If
             
             If .Offset(0, -2).Value = "" Then
                  blFailed = True
                 .Offset(0, -2).Interior.ColorIndex = col2
             Else
                 .Offset(0, -2).Interior.ColorIndex = col
             End If
             If .Offset(0, -4).Value = "" Then
                 blFailed = True
                 .Offset(0, -4).Interior.ColorIndex = col2
             Else
                 .Offset(0, -4).Interior.ColorIndex = col
             End If
             If .Offset(0, 3).Value = "" Then
                 blFailed = True
                 .Offset(0, 3).Interior.ColorIndex = col2
             Else
                 .Offset(0, 3).Interior.ColorIndex = col
             End If
             If .Offset(0, 19).Value = "" Then
                 blFailed = True
                 .Offset(0, 19).Interior.ColorIndex = col2
            Else
                 .Offset(0, 19).Interior.ColorIndex = col
             End If
        End If
    End With
Next i
Range("A12").Select

    If blFailed Then
        MsgBox "Cannot SAVE file! All Cells Colored Red need to be filled in", vbExclamation, "Save Cancelled"
        Cancel = True
    End If


ActiveSheet.Protect
End Sub
0
Comment
Question by:mato01
  • 2
3 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36481023
If I go in and hit the spacebar to empty it ignores the value = "".  

So for example hte

  If .Offset(0, -1).Value = "" Then

can appear empty, but the script does not treat it as such.

Well, you DO NOT "empty" a cell by entering a space.  By doing that, you enter a value: the space.

An empty cell is one that has neither a constant (value) nor a formula.  Thus, a formula that evaluates to a zero length string is NOT empty.

If you want to test whether a cell is empty, use:

  If IsEmpty(.Offset(0, -1)) Then

Open in new window


0
 
LVL 81

Accepted Solution

by:
byundt earned 125 total points
ID: 36481030
Or you could use Trim:

If Trim(.Offset(0, -1).Value) = "" Then
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36481052
Brad,

Depends on what we're looking for.  Do we need an "empty" cell, in which case Trim won't help us (see above), or do we want "a cell that is empty, or all spaces, or a formula that evaluates to a zero length string or all spaces"?

:)

Patrick
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Request to review costing formula 3 36
Merging spreadsheets 8 42
Error 1004: Application-defined or object-defined error 10 17
Formula Help 3 23
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question