Инструкция Excel VBA IF для Msgbox (диапазон1 <> диапазон2 + диапазон3) затем - PullRequest
0 голосов
/ 27 марта 2019

VBA noob здесь,

Итак, у меня есть 3 столбца (A, B и C)

A = Received Goods
B = Sent Goods for Shop 1
C = Sent Goods for Shop 2

Я хочу значения ячеек в B + C = A в противном случае выведите мне сообщение об ошибке.

Вот мой код:

If Range("A1").End(xlDown).Value <> Range("B1").End(xlDown).Value & Range("C1").End(xlDown).Value Then
MsgBox "Error, wrong number of sent goods"
End If

End Sub

1 Ответ

0 голосов
/ 27 марта 2019

Вот оно:

Option Explicit
Sub Warning()

    Dim A As Long, B As Long, C As Long 'in case you have floating numbers use Single or Double instead

    With ThisWorkbook.Sheets("NameOfYourSheet")
        A = .Cells(.Rows.Count, "A").End(xlUp)
        B = .Cells(.Rows.Count, "B").End(xlUp)
        C = .Cells(.Rows.Count, "C").End(xlUp)
    End With

    If B + C <> A Then
        MsgBox "Error, wrong number of sent goods"
    End If

End Sub

Я предполагаю, что вы пробуете последний ряд каждого столбца.

...