就像问你是否知道vlookup样式中的公式,但是它将返回的单元名称不是单元格的值?谢谢!
我想将sal
的值放在Application.WorksheetFunction.VLookup(name, Sheet2.Range("Table6"), 5, False)
中,但在此函数中,单元格内的值将不返回单元格的名称
Sub purchase()
Dim name As String
name = ActiveSheet.Range("C3")
sal = Application.WorksheetFunction.VLookup(name, Sheet2.Range("Table6"), 5, False) - ActiveSheet.Range("d3").Value
MsgBox " remaining: " & sal
End Sub
答案 0 :(得分:0)
VLookup
仅返回一个值。您将需要match
功能。这将返回可用于访问所需单元格的行号。
Sub purchase()
Dim Name As String
Name = ActiveSheet.Range("C3")
Dim MatchedRow As Long
MatchedRow = Application.WorksheetFunction.Match(Name, Sheet2.Range("Table6").Columns(1), 0)
'Find the row number (relative to the range table6) of the found name
Dim Sal As Double
Sal = Sheet2.Range("Table6").Cells(MatchedRow, 5).Value - ActiveSheet.Range("D3").Value
Sheet2.Range("Table6").Cells(MatchedRow, 5).Value = Sal
'Write the calculated Sal back
MsgBox " remaining: " & Sal
End Sub