Match Not working Excel: Error 1004 Unable to get the Match Property

后端 未结 3 1632
遇见更好的自我
遇见更好的自我 2021-01-23 00:10
Sub Sales_Summary_Macro()

    Dim strMake, strModel, strCount As String
    Dim makeLoc, modelLoc, countLoc As Integer

    strMake = Application.InputBox(\"Make\")
            


        
3条回答
  •  臣服心动
    2021-01-23 00:45

    UPD:

    Is it possible to get it to return the cell reference like C1 and then use that cell reference in other functions

    Sub Sales_Summary_Macro()
        Dim strMake As String, strModel  As String, strCount As String
        Dim makeLoc, modelLoc As Integer, countLoc As Integer
        Dim res As Range
        strMake = Application.InputBox("Make")
        strModel = Application.InputBox("Model")
        strCount = Application.InputBox("Count")
    
        If strMake <> "False" Then
            Debug.Print strMake
            Debug.Print strModel
            Debug.Print strCount
            On Error Resume Next
            'Set res = Range("A1:Z1").Find(What:=strMake, LookAt:=xlWhole, MatchCase:=False)
            Set res = Application.Index(Range("A1:A10"), Application.Match(strMake, Range("A1:A10"), 0))
            On Error GoTo 0
            If res Is Nothing Then
                MsgBox "Nothing found!"
                Exit Sub
            End If
            'Print address of result
            Debug.Print res.Address
    
            makeLoc = res.Value
            Debug.Print makeLoc
        End If
    End Sub
    

    BTW,

    when you are using Dim strMake, strModel, strCount As String, only strCount has type String, but strMake, strModel are Variant.

    The same thing with Dim makeLoc, modelLoc, countLoc As Integer - only countLoc has Integer type.

提交回复
热议问题