Marc L
Excel Ninja
No matters as non blank is always superior to empty (> "") …If you want to skip blank cells, just use <>"" rather than >""
No matters as non blank is always superior to empty (> "") …If you want to skip blank cells, just use <>"" rather than >""
So....No matters as non blank is always superior to empty (> "") …
Sub Demo1A()
V = "A"
If V > "" Then Beep
End Sub
Sub Demo2A()
V = "A"
If V <> "" Then Beep
End Sub
Sub Demo1N()
V = 1
If V > "" Then Beep
End Sub
Sub Demo2N()
V = 1
If V <> "" Then Beep
End Sub
Sub Demo3N()
V = 1
If V Then Beep
End Sub
@Debaser is quite right, your
With Ws.[A3:F3].Resize(Ws.Cells(Rows.Count, "A").End(xlUp).Row)
above that is only looking in column A:F, not G which has your pink dates in. The formula removes the CHAR(160) characters successfully though.
But… it wouldn't do just to change that to:
With Ws.[A3:G3].Resize(Ws.Cells(Rows.Count, "A").End(xlUp).Row)
because the formula you evaluate starts with:
IF($A$3:$G$9>"",
and numbers (real dates in cells G5 to G7) are NOT >"". This results in them becoming "" (an empty string, thus losing your real dates)!
So you'd probably be better treating that little range separately.
If you were only to remove CHAR(160) from the string, you'd end up with a string that you'd hope Excel properly interpreted as a date. I say 'hope' because there are always problems with leaving it to Excel to interpret what it thinks are dates. Depending on your locale, it often gets the months and days of the month confused.
So, after your line:
.Value = .Parent.Evaluate(Replace("IF(#>"""",TRIM(CLEAN(SUBSTITUTE(#,CHAR(160),""""))),"""")", "#", .Address))
you could insert the following:
Code:With .Offset(, .Columns.Count).Resize(, 1) 'date completed column rngVals = .Value 'copy values into array in-memory, to work on. For i = 1 To UBound(rngVals) If TypeName(rngVals(i, 1)) = "String" Then rngVals(i, 1) = Replace(rngVals(i, 1), Chr(160), "") If IsDate(rngVals(i, 1)) Then 'does it look like a date? DateParts = Split(rngVals(i, 1), "/") 'assumes your date strings are going to be / delimited. rngVals(i, 1) = DateSerial(DateParts(2), DateParts(0), DateParts(1)) 'converts string to date assuming m/d/yyyy format End If End If Next i .Value = rngVals 'put the updated values back on the sheet End With
And a small thing, that line of code which determines the cells you're looking at:
With Ws.[A3:F3].Resize(Ws.Cells(Rows.Count, "A").End(xlUp).Row)
ends up having 2 too many rows (because it starts in row 3, not row 1) so you could tweak that line to:
With Ws.[A3:F3].Resize(Ws.Cells(Rows.Count, "A").End(xlUp).Row - 2)