Function paix(salary) As Integer h = 2 Do While Sheet1.Cells(h, 1) <> "" If salary >= Sheet1.Cells(h, 1) Then xh = h - 1 Exit Do End If h = h + 1 Loop paix = h End Function
喵喵时光机
浏览 239回答 2
2回答
桃花长相依
函数里不宜直接调用与工作表名称有关的数据例如:“Sheet1.Cells(h, 1)”,建议把它作为参数传递入函数,建议把函数改成如下:调用的时候可以这样:=paix(A10,Sheet1!A1:A20),这样就与表格名称无关了。Function paix(salary As Integer, AR As Range) As IntegerDim R As Range,h As Integerh = 2For Each R In AR.RowsIf R.Cells.Item(1) = "" Then Exit ForIf salary >= R.Cells.Item(1) Thenpaix = h - 1Exit FunctionElseh = h + 1End IfNextpaix = hEnd Function