在选定范围内偏移最大数

时间:2019-12-15 20:08:59

标签: excel vba

我希望函数选择一个范围作为输入。然后找到范围的前5个数字。找到前5个数字后,我需要选择下面的数字的功能。我的VBA函数只能找到前5个数字。我不知道为什么任何代码都不起作用。谢谢。

enter image description here

enter image description here

Function Getnum(row) As Integer
Dim Rng As Range, cell As Range
Dim firstVal As Double, secondVal As Double, thirdVal As Double, fourthVal As Double

Set Rng = row
Range("row").Select
Rng("row").Select

firstVal = Application.WorksheetFunction.Large(Rng, 1)
'Rng("firstVal").Select
'Ret1 = Rng("firstVal").Offset(4, 0).Select
'Range("firstVal").Select
'Ret1 = Range("firstVal").Offset(4, 0).Select
'ActivatefirstVal =
'strMyValue = ActiveCell.Offset(4, 0).Value
'Ret1 = ActiveCell.Offset(3, 0).cell("firstVal")

'secondVal = Application.WorksheetFunction.Large(Rng, 2)
'thirdVal = Application.WorksheetFunction.Large(Rng, 3)
'fourthVal = Application.WorksheetFunction.Large(Rng, 4)

MsgBox "First Highest Value is " & firstVal
'MsgBox "Second Highest Value is " & secondVal
'MsgBox "Third Highest Value is " & thirdVal
'MsgBox "Fourth Highest Value is " & fourthVal
MsgBox "First Highest Ret " & Ret1

End Function

0 个答案:

没有答案