根据输入值,我想在表中找到单元格,并将行号存储在变量中。此变量将用于将下一列中的相应值与输入数相乘。到目前为止我的代码:
Option Explicit
Sub Calculate()
Dim var As Variant
Dim rownumber As Integer
Dim Mx As Variant
Dim Nx As Variant
Dim Ox As Variant
Dim Px As Variant
Dim Qx As Variant
Dim Rx As Variant
Dim low As Variant
Dim cat As Variant
rownumber = WorksheetFunction.Match(Sheets("User Interface").Range("K27").Value, Sheets("C-type").Range("L5:L345"), 0)
Mx = Sheets("User Interface").Range("K27").Value * Sheets("C-type").Range("M" & rownumber).Value
Nx = Sheets("User Interface").Range("K27").Value * Sheets("C-type").Range("N" & rownumber).Value
Ox = Sheets("User Interface").Range("K27").Value * Sheets("C-type").Range("O" & rownumber).Value
Px = Sheets("User Interface").Range("K27").Value * Sheets("C-type").Range("P" & rownumber).Value
Qx = Sheets("User Interface").Range("K27").Value * Sheets("C-type").Range("Q" & rownumber).Value
Rx = Sheets("User Interface").Range("K27").Value * Sheets("C-type").Range("R" & rownumber).Value
cat = Array(Mx, Nx, Ox, Px, Qx, Rx)
low = Application.WorksheetFunction.Min(cat)
Sheets("User Interface").Range("C45").Value = low
Sheets("User Interface").Range("c45").Activate
Application.Goto ActiveCell.EntireRow, True
End Sub
问题是我在匹配函数上得到了下标范围错误,因此我开始怀疑这是正确的方法。我需要以某种方式能够引用表中匹配数字的行号,任何建议都将受到高度赞赏。
答案 0 :(得分:1)
试试这个


 strToFind = ThisWorkbook.Sheets(“用户界面”)。范围(“K27”)。值
设置Rng = ThisWorkbook.Sheets(“C-type”)。范围(“L5:L345”)
如果Application.WorksheetFunction.CountIf(Rng,strToFind)> 0然后
设置Rng1 = Rng.Find(strToFind,LookIn:= xlValues,LookAt:= xlWhole)
 rownumber = Rng1.Row
否则
 MsgBox strToFind& “范围内不存在”& Rng.Address
结束如果