Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty and "" not working 1

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
Here's a brand new one for me.

The code is checking to see if the cells used to verify information and hold information are blank and if they are its to turn an indicator called Flag to 1. Problem is, the worksheet is blank, the cells are all empty and the if statment isn't turning Flag to 1.

If I highlight the section of code that shows the value of the cell it says the cell is empty but for some reason the if statment simply skips turning the flag indicator to 1.

Neither I nor my co-workers can figure out why. We have deleted all the cells, replaced all the cells and even populated a few of the cells to check if the values were pulling through (they are) but we simply can't get Flag = 1.

We have tried = Empty and = "" but neither works.

Ideas?

Here is some preceding code and the entire sub that checks the cell data, J is the counter used in the next loop that calls this sub and it indicates which worksheet in the workbook to look at.

Public J as long
Public Flag As Byte
Public WS_Count As Integer

WS_Count = Application.Sheets.Count

for J = 1 to WS_Count

' Do stuff like open workbook, get workbook name and path

Check_For_Data

' Do more stuff or go to the next worksheet

Next J


Private Sub Check_For_Data()

If Trim(Worksheets(J).Range("AD25").Value) = Empty And _
Trim(Worksheets(J).Range("AF35").Value) = Empty And _
Trim(Worksheets(J).Range("AJ35").Value) = Empty And _
Trim(Worksheets(J).Range("AK35").Value) = Empty And _
Trim(Worksheets(J).Range("AL35").Value) = Empty And _
Trim(Worksheets(J).Range("ar35").Value) = Empty And _
Trim(Worksheets(J).Range("D1").Value) = Empty And _
Trim(Worksheets(J).Range("E25").Value) = Empty And _
Trim(Worksheets(J).Range("E3").Value) = Empty And _
Trim(Worksheets(J).Range("H26").Value) = Empty And _
Trim(Worksheets(J).Range("H28").Value) = Empty And _
Trim(Worksheets(J).Range("h3").Value) = Empty And _
Trim(Worksheets(J).Range("H9").Value) = Empty And _
Trim(Worksheets(J).Range("i3").Value) = Empty And _
Trim(Worksheets(J).Range("J3").Value) = Empty And _
Trim(Worksheets(J).Range("J5").Value) = Empty And _
Trim(Worksheets(J).Range("k10").Value) = Empty Then

Flag = 1

End If


If Trim(Worksheets(J).Range("K32").Value) = Empty And _
Trim(Worksheets(J).Range("K33").Value) = Empty And _
Trim(Worksheets(J).Range("K5").Value) = Empty And _
Trim(Worksheets(J).Range("R5").Value) = Empty And _
Trim(Worksheets(J).Range("R7").Value) = Empty And _
Trim(Worksheets(J).Range("S25").Value) = Empty And _
Trim(Worksheets(J).Range("S26").Value) = Empty And _
Trim(Worksheets(J).Range("U3").Value) = Empty And _
Trim(Worksheets(J).Range("U35").Value) = Empty And _
Trim(Worksheets(J).Range("u5").Value) = Empty And _
Trim(Worksheets(J).Range("V35").Value) = Empty Then

Flag = 1

End If

End Sub
 

hi,
Code:
    With Worksheets(J)
        If Trim(.Range("AD25").Value) = "" And _
            Trim(.Range("AF35").Value) = "" And _
            Trim(.Range("AJ35").Value) = "" And _
            Trim(.Range("AK35").Value) = "" And _
            Trim(.Range("AL35").Value) = "" And _
            Trim(.Range("ar35").Value) = "" And _
            Trim(.Range("D1").Value) = "" And _
            Trim(.Range("E25").Value) = "" And _
            Trim(.Range("E3").Value) = "" And _
            Trim(.Range("H26").Value) = "" And _
            Trim(.Range("H28").Value) = "" And _
            Trim(.Range("h3").Value) = "" And _
            Trim(.Range("H9").Value) = "" And _
            Trim(.Range("i3").Value) = "" And _
            Trim(.Range("J3").Value) = "" And _
            Trim(.Range("J5").Value) = "" And _
            Trim(.Range("k10").Value) = "" Then
        
            Flag = 1
        
        End If
        
        
        If Trim(.Range("K32").Value) = "" And _
            Trim(.Range("K33").Value) = "" And _
            Trim(.Range("K5").Value) = "" And _
            Trim(.Range("R5").Value) = "" And _
            Trim(.Range("R7").Value) = "" And _
            Trim(.Range("S25").Value) = "" And _
            Trim(.Range("S26").Value) = "" And _
            Trim(.Range("U3").Value) = "" And _
            Trim(.Range("U35").Value) = "" And _
            Trim(.Range("u5").Value) = "" And _
            Trim(.Range("V35").Value) = "" Then
        
            Flag = 1
        
        End If
    End With

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
If IsEmpty(Range("A1").Value) Then
MsgBox "Empty"
End If

If Range("A1").Value = "" Then
MsgBox """"
End If

If Range("A1").Value = vbEmpty Then
MsgBox "vbEmpty"
End If
 

VBA_Help said:
IsEmpty Function

Returns a Boolean value indicating whether a variable has been initialized.


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top