当列中的任何值与指定值匹配时显示 MsgBox

Display a MsgBox when any value in a column matches specified value

我想在

时显示一个 MsgBox

我收到错误。

列中的所有值都是字符串

Sub Booluno()
Dim concepto As Excel.Range
Set concepto = ThisWorkbook.Worksheets("Base 2019").Range("AT6:AT1040")

Dim valoresconcepto As String
valoresconcepto = concepto.Value

Dim request As Excel.Range
Set request = ThisWorkbook.Worksheets("Base 2019").Range("I6:I1040")

Dim valoresrequest As String
valoresrequest = request.Value

Dim Bool As Boolean

If valoresconcepto = "Inexistente" And valoresrequest <> "*" Then
    Bool = True

ElseIf valoresconcepto = "Inexistente" And valoresrequest = "*" Then
    Bool = False
    
End If

If Bool = True Then
    MsgBox "Ojo, Hay nuevos conceptos por agregar para los requerimientos"
    
    If Bool = False Then
        MsgBox "No hay nuevos conceptos por añadir, puedes subir el archivo a nuestra carpeta una vez termines :)"
    
    End If
End If
End Sub

这些是有问题的:

valoresconcepto = concepto.Value

valoresrequest = request.Value

由于 conceptorequest 是多单元格范围,它们的 .Value 是二维变体数组,而不是 String

简化的一个选项是使用 WorksheetFunction.CountIfs 或其后期绑定形式 Application.CountIfs,使用 ~ 转义 *

If Application.CountIfs(concepto, "Inexistente") > 0 Then
    If Application.CountIfs(request, "~*") = 0 Then
        MsgBox "Ojo, Hay nuevos conceptos por agregar para los requerimientos"
    Else
        MsgBox "No hay nuevos conceptos por añadir, puedes subir el archivo a nuestra carpeta una vez termines :)"
    End If
End If

你需要循环:

For i = 1 to request.Rows.Count
    if concepto.Cells(i, 1).Value = "*" Then
        Msg box("blah blah 1")
        Exit For
    EndIf

    if request.Cells(i, 1).Value = "Inexistante" Then
        Msg box("blah blah 2")
        Exit For
    EndIf
Next