匹配不工作Excel:错误1004无法获取匹配属性 [英] Match Not working Excel: Error 1004 Unable to get the Match Property

查看:166
本文介绍了匹配不工作Excel:错误1004无法获取匹配属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sub Sales_Summary_Macro()

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

    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
        makeLoc = WorksheetFunction.Match(strMake, Range("A1:A10"), 0)
        Debug.Print makeLoc
    End If

End Sub

我只想在三个不同的变量上使用用户的字符串输入,并找到包含每个变量的列。我已经尝试过Application.Match()和Match(),并且似乎都不起作用。

I just want to take the string input of the user on three different variables and find the column that contains each variable. I have tried Application.Match() and Match() alone and neither seem to work.

推荐答案

UPD:


可以让它返回像C1一样的单元格引用,然后在其他函数中使用该单元格引用

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, strong>

BTW,

当您使用 Dim strMake,strModel,strCount As String ,只有 strCount 具有 String ,但 strMake,strModel 变体

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

相同的东西Dim makeLoc,modelLoc,countLoc As Integer - 只有 countLoc 整数类型。

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

这篇关于匹配不工作Excel:错误1004无法获取匹配属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆