Logic statement trouble

Mr930

Well-known Member
Joined
Aug 31, 2006
Messages
585
I am passing in these values:
szOld=PDP
szNew=empty

Function FindType(szOld As String, szNew As String)
If ((szOld = "PDP" Or szOld = "PDNP" Or szOld = "PUD") And IsEmpty(szNew)) Then
FindType = "delete"
End If
End Function

Something must be wrong with my logic, or I am still thinking in C, but it seems like my IF statement should evaluate to true, but it is false.

Can someone guide me?

thanks
Fred Emmerich
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What is happening is that szNew isn't empty, is it a null string: ""

Try:
Code:
Function FindType(szOld As String, szNew As String)
If (szOld = "PDP" Or szOld = "PDNP" Or szOld = "PUD") And szNew = "" Then
    FindType = "delete"
End If
End Function
 
Upvote 0
According to the VBA Help file for IsEmpty:

"IsEmpty will only return TRUE for a variable that is unitialized, or is explicitly set to Empty."

Since you initialized the variable, and it is not explicitly set to EMPTY, IsEmpty is evaluating to FALSE.
 
Upvote 0
To test for an 'empty' string you could try checking the length.

If (...) And Len(szNew)=0 Then
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top