簡體   English   中英

vlookup,但將返回的單元格名稱不是該單元格中的值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM