我已经尝试了一些内置函数,但我没有太多运气,因为它们返回null。 例如:选择强制转换(date_format('1-Nov-2012','yyyy-MM-dd HH:mm:ss')作为时间戳)为tstp;返回null。
写一个UDF是唯一的方法还是我错过了什么?
答案 0 :(得分:0)
您需要将字符串转换为日期,而不是相反。所以,试试这个:
Dim i As Long, lr As Long, nodel As Boolean
Dim mDiff1 As Double, mDiff2 As Double, mDiff3 As Double, mDiff4 As Double
mDiff1 = 0.01
mDiff2 = 0.03
mDiff3 = 0.01
mDiff4 = 0.03
With Worksheets("po")
lr = Application.Max(.Cells(.Rows.Count, "U").End(xlUp).Row, _
.Cells(.Rows.Count, "AB").End(xlUp).Row)
For i = lr To 2 Step -1
nodel = False
If .Cells(i, "U").Value2 - .Cells(i, "U").Offset(0, 1).Value2 > mDiff1 Then
.Cells(i, "U").Offset(0, 1).Interior.ColorIndex = 3
nodel = True
End If
If .Cells(i, "U").Value2 - .Cells(i, "U").Offset(0, 2).Value2 > mDiff2 Then
.Cells(i, "U").Offset(0, 2).Interior.ColorIndex = 5
nodel = True
End If
If .Cells(i, "AB").Value2 - .Cells(i, "AB").Offset(0, 1).Value2 > mDiff3 Then
.Cells(i, "AB").Offset(0, 1).Interior.ColorIndex = 3
nodel = True
End If
If .Cells(i, "AB").Value2 - .Cells(i, "AB").Offset(0, 2).Value2 > mDiff4 Then
.Cells(i, "AB").Offset(0, 2).Interior.ColorIndex = 5
nodel = True
End If
If Not nodel Then
.Rows(i).EntireRow.Delete
End If
Next i
End With
如果你真的想要,你可以将它转换回字符串。