[英]vlookup but the name of the cell that will return not the value in the cell
就像问您是否知道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
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.