我正在尝试在Excel中编写一组VBA过程。该过程的目的是查看表中的数据,对特定列中的值进行平均,然后突出显示高于该平均值的每个值。
我的困境是我不断得到一个" Argument Not Optional"我尝试运行代码时出错。我完全理解这个错误通常会表明什么。但是,我无法理解为什么我传入程序的两个字符串不被接受?提前感谢您的帮助..
Sub HighlightLarge()
Call HighlightProductOrders(">", "vbYellow")
End Sub
Sub HighlightProductOrders(FunctionType As String, HighlightColor As String)
'Delete all previous conditional formatting
Cells.FormatConditions.Delete
'Make a variable to dynamically cover an entire table range
Dim FormatTable As Range
Set FormatTable = Range(Range("AllOrders").Offset(1, 0), Range("AllOrders").End(xlDown).End(xlToRight))
'Make a variable to calculate average order quantity
Dim AverageQuantity As Double
AverageQuantity = Application.WorksheetFunction.Average(FormatTable.Columns(2))
'Perform Highlighting based on Sub's params
Dim i As Integer
i = 1
If FunctionType = ">" Then
Do Until Range("AllOrders").Offset(i, 0) = ""
If Range("AllOrders").Offset(i, 1) > AverageQuantity Then
Range("AllOrders").Offset(i, 0).Interior.Color = HighlightColor
Range("AllOrders").Offset(i, 1).Interior.Color = HighlightColor
Range("AllOrders").Offset(i, 2).Interior.Color = HighlightColor
End If
Loop
ElseIf FunctionType = "<" Then
Do Until Range("AllOrders").Offset(i, 0) = ""
If Range("AllOrders").Offset(i, 1) < AverageQuantity Then
Range("AllOrders").Offset(i, 0).Interior.Color = HighlightColor
Range("AllOrders").Offset(i, 1).Interior.Color = HighlightColor
Range("AllOrders").Offset(i, 2).Interior.Color = HighlightColor
End If
Loop
Else
MsgBox "Parameters were not as expected.", vbCritical, "Error!"
Exit Sub
End If
End Sub