PDA

View Full Version : checking for space bar



talytech
03-19-2009, 06:41 AM
I'm trying to check for null string in a cell and my code works but if the user hits the space bar several times in a cell it acts as if its something there. How can I check for that. I thought that would be the same as null but apparently not. Here's my code where the variable "a" is the row number.




If a > 20 And Cells(a, "b").Value = "" And Cells(a, "f").Value = "" And Cells(a, "i").Value = "" And Cells(a, "j").Value = "" And Cells(a, "k").Value = "" And (Cells(a, "l").Value = "" And Cells(a, "m").Value = "" And Cells(a, "n").Value = "" And Cells(a, "o").Value = "") Then
response = MsgBox("Are you done?", vbCritical + vbYesNo, "Bulk Exception Request Form")

If response = vbYes Then
RiskForm.Show
Exit Sub
Else
Exit Sub

End If
ElseIf a > 20 And Cells(a, "b").Value = "" Then
MsgBox "Please enter the first name for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf a > 20 And Cells(a, "f").Value = "" Then
MsgBox "Please enter the last name for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf a > 20 And Cells(a, "i").Value = "" Then
MsgBox "Please enter the SSN for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf a > 20 And Cells(a, "j").Value = "" Then
MsgBox "Please enter the DOB for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf a > 20 And Cells(a, "k").Value = "" Then
MsgBox "Please enter the vendor for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf a > 20 And Cells(a, "l").Value = "" And Cells(a, "m").Value = "" And Cells(a, "n").Value = "" And Cells(a, "o").Value = "" Then
MsgBox "Please select the type of access for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub

Bob Phillips
03-19-2009, 06:57 AM
If a > 20 Then

If Trim(Cells(a, "b").Value) = "" And _
Trim(Cells(a, "f").Value) = "" And _
Trim(Cells(a, "i").Value) = "" And _
Trim(Cells(a, "j").Value) = "" And _
Trim(Cells(a, "k").Value) = "" And _
Trim(Cells(a, "l").Value) = "" And _
Trim(Cells(a, "m").Value) = "" And _
Trim(Cells(a, "n").Value) = "" And _
Trim(Cells(a, "o").Value) = "" Then
response = MsgBox("Are you done?", vbCritical + vbYesNo, "Bulk Exception Request Form")

If response = vbYes Then
RiskForm.Show
Exit Sub
Else
Exit Sub

End If
ElseIf Trim(Cells(a, "b").Value) = "" Then
MsgBox "Please enter the first name for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf Trim(Cells(a, "f").Value) = "" Then
MsgBox "Please enter the last name for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf Trim(Cells(a, "i").Value) = "" Then
MsgBox "Please enter the SSN for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf Trim(Cells(a, "j").Value) = "" Then
MsgBox "Please enter the DOB for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf Trim(Cells(a, "k").Value) = "" Then
MsgBox "Please enter the vendor for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
ElseIf Trim(Cells(a, "l").Value) = "" And Trim(Cells(a, "m").Value) = "" And _
Trim(Cells(a, "n").Value) = "" And Trim(Cells(a, "o").Value) = "" Then
MsgBox "Please select the type of access for row " & a, vbCritical, "Required fields missing"
Cancel = True
Exit Sub
End If
End If

talytech
03-19-2009, 07:08 AM
Nevermind .. I fixed it. Thanks