所以我正在研究一个udf,我最终将其作为一个插件来帮助处理数据,如果可以突出显示单元格以吸引用户注意任何问题,那将是首选。
udf如下:
WHERE DateDiff("m", t.AllDate, Date()) < 2
&#34; threecfs&#34; sub是
Function AnalyzeData()
Dim Headers() As Variant
Dim Row1 As Variant
Headers = Array(Row1, Row2, Row3, Row4, Row5)
Row1 = Array("Final Curve", "", "Cr", "Fe", "Ni", "Cu", "Zn", "As", "Ag", "Cd", "Sn", "Pb")
Row2 = Array("Level", "Nominal", 100, 100, 100, 100, 100, 100, 100, 100, 100, 100)
col1 = Array("Level", "Cal 1", "Cal 2", "Cal 3", "Cal 4", "Cal 5", "Cal 6", "Cal 7", "Cal 8", "Cal 9", "Cal 10", "", "", "Level", "Cal 1", "Cal 2", "Cal 3", "Cal 4", "Cal 5", "Cal 6", "Cal 7", "Cal 8", "Cal 9", "Cal 10", "", "")
col2 = Array("", "Nominal", "0.1", "0.2", "0.5", "1.0", "2.5", "5.0", "10", "20", "30", "50", "", "", "Nominal", "0.1", "0.2", "0.5", "1.0", "2.5", "5.0", "10", "20", "30", "50", "", "")
Dim Location() As Variant
Select Case TypeName(Application.Caller)
Case "Range"
Location = Array(Application.Caller.Row, Application.Caller.Column)
If Location(0) = 1 And Location(1) = 1 Then
BuildArrays
MethodCheck
On Error Resume Next
threecf
AnalyzeData = Row1(0)
Else
Select Case Location(1)
Case 1 - 2
Case 1
AnalyzeData = col1(Location(0) - 2)
Case 2
AnalyzeData = col2(Location(0) - 1)
Case Else
Select Case Location(0)
Case 1, 14
AnalyzeData = SelectedAnalytes(Location(1) - 3)
Case 2, 15
AnalyzeData = Row2(Location(1) - 1)
Case 3 To 12
AnalyzeData = Round(STDArray(Location(0) - 2,Location(1) - 3), 3)
Case 13, 26
AnalyzeData = ""
Case 16 To 25
If CalValues(Location(1) - 3, Location(0) - 15) = "" Then
AnalyzeData = "N/A"
ElseIf Round(STDArray(Location(0) - 15, Location(1) - 3) / CalValues(Location(1) - 3, Location(0) - 15) * 100, 0) <= 100 + Acceptance And Round(STDArray(Location(0) - 15, Location(1) - 3) / CalValues(Location(1) - 3, Location(0) - 15) * 100, 0) >= 100 - Acceptance Then
AnalyzeData = Round(STDArray(Location(0) - 15, Location(1) - 3) / CalValues(Location(1) - 3, Location(0) - 15) * 100, 0) & "%"
Else
AnalyzeData = "Fail acceptance"
End If
End Select
End Select
End If
Case "String"
AnalyzeData = Application.Caller
Case "Error"
AnalyzeData = "Error"
Case Else
AnalyzeData = "unknown"
End Select
End Function
我通过在线寻找帮助找到了这个。 所以没有线
Public Sub threecf()
Dim rg As Range
Dim cond1 As FormatCondition, cond2 As FormatCondition, cond3 As FormatCondition
Set rg = Range("C2", Range("C2").End(xlDown))
'clear any existing conditional formatting
rg.FormatConditions.Delete
'define the rule for each conditional format
Set cond1 = rg.FormatConditions.Add(xlCellValue, xlGreater, "=1")
Set cond2 = rg.FormatConditions.Add(xlCellValue, xlLess, "=$a$1")
Set cond3 = rg.FormatConditions.Add(xlCellValue, xlEqual, "=$a$1")
'define the format applied for each conditional format
With cond1
.Interior.Color = vbGreen
.Font.Color = vbWhite
End With
With cond2
.Interior.Color = vbRed
.Font.Color = vbWhite
End With
With cond3
.Interior.Color = vbYellow
.Font.Color = vbRed
End With
End Sub
我的功能适当地工作和分析数据,但是当&#34; threecf&#34; sub由单元格A1调用,它的错误不会在没有&#34;的情况下继续下一步&#34;并且根本不应用条件格式。
如果范围在&#34; threecf&#34;改为
On Error Resume Next
threecf
然后该函数仍然需要&#34;错误恢复下一个&#34;,但是应用了条件格式但不正确。它添加了条件,但没有为每个条件设置格式。
如果我跑&#34; threecfs&#34;通过F5然后它可以正常工作。
我对通过udf应用条件格式的理解不正确,因为这不能做到吗?
理想情况下,我的udf将根据我的数据计算值的恢复百分比,条件格式将应用于突出显示有问题的值,但这是否需要由每个单元格而不是应用它的起始单元格完成?“ p>