Динамическое окно сообщения - недопустимый вызов процедуры или аргумент - PullRequest
0 голосов
/ 18 апреля 2019

У меня есть два макроса, назначенных кнопкам, которые делают одно и то же.Они извлекают информацию из ячеек в другой рабочей таблице («Объединенная») на основе активной ячейки («Имя свойства»), а затем отображают их в окне сообщения.Второй макрос дает мне ошибку времени выполнения 5 в строке, начинающейся с «зрелости».

Sub PropertyInfo()
Application.ScreenUpdating = False
Application.DisplayAlerts = False

Dim ArrayRange As Variant
Dim ActCell As Variant

Set ActCell = ActiveCell
PropertyName = ActiveCell.Value

If IsEmpty(ActiveCell) = True Or IsNumeric(ActiveCell) = True Then
    MsgBox "Please select Property Name"    
Else
    Sheets("Combined").Select
    ArrayRange = Sheets("Combined").Range(Range("F1"), Range("F1").SpecialCells(xlLastCell))
    Sheets("Pivot").Select

    Maturity = Application.WorksheetFunction.VLookup(ActCell, ArrayRange, 36, False)
    Lender = Application.WorksheetFunction.VLookup(ActCell, ArrayRange, 41, False)
    Originator = Application.WorksheetFunction.VLookup(ActCell, ArrayRange, 42, False)
    Address = Application.WorksheetFunction.VLookup(ActCell, ArrayRange, 2, False)

    MsgBox "Property Name: " & PropertyName & vbCrLf & vbCrLf & "Loan Maturity: " & Maturity & vbCrLf & vbCrLf & "Lender: " & Lender & vbCrLf & vbCrLf & "Originator: " & Originator & vbCrLf & vbCrLf & "Property Address: " & Address & vbCrLf & vbCrLf & "Note: If dates are blank, the database doesnt have the info."

    Application.ScreenUpdating = True

End If

End Sub

конечный результат отобразит окно сообщения с погашением, кредитором, отправителем и адресом

1 Ответ

1 голос
/ 23 апреля 2019

В этом случае нет необходимости использовать массив.

Попробуйте что-то вроде этого:

Sub PropertyInfo()
    Dim lf2
    Dim PropertyName As Variant, m, shtCombined As Worksheet

    lf2 = vbLf & vbLf

    Set shtCombined = Sheets("Combined")
    PropertyName = ActiveCell.Value

    If Len(PropertyName) = 0 Or IsNumeric(PropertyName) = True Then
        MsgBox "Please select Property Name"
    Else
        'find the matching row number
        m = Application.Match(PropertyName, shtCombined.Range("F:F"), 0)

        If Not IsError(m) Then       '<< found a match?
            With shtCombined.Rows(m)
                '###adjust the column numbers below...###
                MsgBox "Property Name: " & PropertyName & lf2 & _
                "Loan Maturity: " & .Cells(41).Value & lf2 & _
                "Lender: " & .Cells(41).Value & lf2 & _
                "Originator: " & .Cells(41).Value & lf2 & _
                "Property Address: " & .Cells(41).Value & lf2 & _
                "Note: If dates are blank, the database doesnt have the info."
            End With
        Else
            MsgBox "No match found for '" & PropertyName & "'!"
        End If

    End If

End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...