【求助】请问如何查找最大值?

来源:百度知道 编辑:UC知道 时间:2024/06/04 17:38:48
【求助】请问如何查找最大值?
大家好

现在我遇到了一个难题

EXCEL表格里面
有一千多行的价钱 一共有三列(价格1)(价格2)(价格3)

然后 我想找出每一行里面的最大值 然后标出红色

请问怎么做呢?

以Cells方式表示单元格——Cells(行,列),以下假设(价格1)(价格2)(价格3)分别处于第1、2、3列。
打开EXCEL表格之后,按Alt+F11,在左上部分的“工程”子窗口选择插入模块,将以下代码粘贴进模块,保存之后,就能使用这个名为Macro的宏来进行你所说的动作了。

Sub Macro()
On Error Resume Next
Dim i%
For i = 1 To ActiveSheet.UsedRange.Rows.Count
If Cells(i, 1) > Cells(i, 2) And Cells(i, 1) > Cells(i, 3) Then Cells(i, 1).Font.ColorIndex = 3
If Cells(i, 2) > Cells(i, 1) And Cells(i, 2) > Cells(i, 3) Then Cells(i, 2).Font.ColorIndex = 3
If Cells(i, 3) > Cells(i, 1) And Cells(i, 3) > Cells(i, 2) Then Cells(i, 3).Font.ColorIndex = 3
Next
End Sub

我的方法比较巧,不过也稍微有点笨吧。
比如:
(价格1)(价格2)(价格3)
13 34 98 然后在它的后面用MAX函数找出这行最大的数(这里是98),找出来后,在选中这行,然后用条件格式,使值=98的用红色标出即可。