首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Excel VBA语句用于Msgbox (range1<>range2+range3)

Excel VBA语句用于Msgbox (range1<>range2+range3)
EN

Stack Overflow用户
提问于 2019-03-27 12:03:09
回答 1查看 41关注 0票数 0

VBA noob在这里,

所以我有3列(A,B和C)

代码语言:javascript
运行
复制
A = Received Goods
B = Sent Goods for Shop 1
C = Sent Goods for Shop 2

我想要B+C =中的值单元格,否则会给我一条错误消息。

这是我的代码:

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-27 12:07:20

就是这样:

代码语言:javascript
运行
复制
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

我假设你正在尝试每一列的最后一行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55376736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档