求教大神,有三列数据A、B、C,想实现筛选出A最大且B小于某值时相应的C值,并且将此C值输出到指定单元格;如果出现A值相同的情况,则筛选出两者对应C值较小的C值并输出,能否实现?代码如何写?
Private Sub CommandButton1_Click()
Dim n As Double
n = Range("A65536").End(xlUp).Row
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A:A")
m = Application.WorksheetFunction.Max(myRange)
Dim y, f
For i = 1 To n
If Cells(i, "A") = m And Cells(i, "B") < 900 Then
If f = False Then
y = Cells(i, "C")
f = True
Else
If y > Cells(i, "C") Then y = Cells(i, "C")
End If
End If
Next
Range("D1") = y
End Sub
仿照别人的写的,但是指定输出的单元格是空白的,是哪里有问题?
Private Sub CommandButton1_Click()
Dim n As Double
n = Range("A65536").End(xlUp).Row
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A:A")
m = Application.WorksheetFunction.Max(myRange)
Dim y, f
For i = 1 To n
If Cells(i, "A") = m And Cells(i, "B") < 900 Then
If f = False Then
y = Cells(i, "C")
f = True
Else
If y > Cells(i, "C") Then y = Cells(i, "C")
End If
End If
Next
Range("D1") = y
End Sub
仿照别人的写的,但是指定输出的单元格是空白的,是哪里有问题?