输入框和Xlookup功能

问题描述 投票:0回答:1

我是 VBA 新手,并尝试根据以下内容在 VBA 中创建宏。

XLookup 向后计数列,而不是 Vlookup。一旦公式找到单元格,我想用输入框中输入的数字替换它。

Here is what I tried.  I know the replace with line is incorrect.  I am able to return a value for the Xlookup. I just can't figure out the correct piece to add in the replacewith line. 

Sub Macro2()
'
' Macro2 Macro
'
Dim myValue As Variant
myValue = InputBox("Enter Club Number")
Range("A1").Value = myValue
myValue2 = InputBox("Enter UNL, PREM, or DSL")
Range("B1").Value = myValue2
Range("C1").Value = Range("A1").Value & Range("B1")
Dim Lookup_Value As String
Dim Lookup_Array As Range
Dim Return_Array As Range
Dim If_Not_Found As String
Dim Result As Variant
  Lookup_Value = Range("A1").Value & Range("B1")
  Set Lookup_Array = Range("O:O")
  Set Return_Array = Range("D:D")
  If_Not_Found = "N/A"
  On Error GoTo CompatibilityIssue
Result = Application.WorksheetFunction.XLookup( _
      Lookup_Value, _
      Lookup_Array, _
      Return_Array, _
      If_Not_Found)


replacewith.InputBox ("Enter New Price")
  Exit Sub
CompatibilityIssue:
  MsgBox "It does not appear that you have access to the XLOOKUP Function"

End Sub
excel vba replace inputbox xlookup
1个回答
0
投票

使用VBA方式而不是XLOOKUP来完成。那么 Excel 365 并不是您解决方案的必备工具。

Sub Macro2()
    Dim myValue, myValue2, myValue3
    Dim c As Range, Lookup_Rng As Range
    myValue = InputBox("Enter Club Number")
    myValue2 = InputBox("Enter UNL, PREM, or DSL")
    Lookup_Value = myValue & myValue2
    Set Lookup_Rng = Application.Intersect(Range("O:O"), ActiveSheet.UsedRange)
    Set c = Lookup_Rng.Find(myValue2, , , xlWhole)
    If Not c Is Nothing Then
        myValue3 = InputBox("Enter New Price")
        Cells(r.Row, "D").Value = myValue3
    End If
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.