I am converting some code from VB6 to .NET. I am having an issue evaluating an excel cell as empty.
The goal is to see if an excel cell is empty and, if so, give it the contents of the cell in the column before it. Looping through rows, If the cell in column 8 is blank, replace it with the value in column 7 and format it as a date.
The pre-conversion code is:
If Not .Cells(LoopIndex, 8) = “” Then .Cells(LoopIndex, 8) = Format(.Cells(LoopIndex, 7), “mm/dd/yyyy”)
The .Net conversion offers:
If Not (.Cells._Default(LoopIndex, 8) = “”) Then .Cells._Default(LoopIndex, 8) = VB6.Format(.Cells._Default(LoopIndex, 7), “mm/dd/yyyy”)
Using the conversion as-is I get
*** ERROR *** Overload resolution failed because no Public ‘=’ can be called with these arguments: ‘Public Shared Operator =(a As String, b As String) As Boolean’: Argument matching parameter ‘a’ cannot convert from ‘__ComObject’ to ‘String’.
So, trying to evaluate the comObject I use .ToString to evaluate the content of the cell:
If Not (.Cells._Default(LoopIndex, 8).ToString = “”) Then .Cells._Default(LoopIndex, 8) = VB6.Format(.Cells._Default(LoopIndex, 7), “mm/dd/yyyy”)
Now it runs without errors, but one problem. The condition is never satisfied. The “cell/string” appears to never be blank, null, nothing, isnullorempty, or an empty string even if I Trim it, even though I cannot see anything in it.
Is my problem in how I am using the comObject or the fact that the cell isnt truly empty? How can I find out what is in that cell and how can I evaluate it for this condition? I appreciate any help in understanding how this cell range is being used further.