【问题标题】:VBA How to make a msgbox to repeat only once for certain valuesVBA如何使msgbox对某些值仅重复一次
【发布时间】:2018-06-15 06:51:51
【问题描述】:

在迭代所有单元格后,我试图只打印 msgbox 的一部分。所以我只需要一次重复——所有找到的单元格只需要一次。这是整个消息框:

我只想打印消息框的这一部分:

这是代码:

Sub checkcolumns()

Dim rngCheck As Range
Dim cell As Range, j As String, mess As String
Dim TextBlockCanBeDefined, noTextBlockCanBeDefined As String

   Set rngCheck = Range("B3:B6")

For Each cell In rngCheck
If IsEmpty(cell) Then

    j = j & cell.Address(0, 0) & vbNewLine
    If cell.Offset(, 1).Value = "L" Then
        TextBlockCanBeDefined = TextBlockCanBeDefined & j & vbNewLine

    ElseIf cell.Offset(, 1).Value = "T" Then
        noTextBlockCanBeDefined = noTextBlockCanBeDefined & j & vbNewLine

    End If

End If
Next cell


mess = vbCrLf & "For the line paragraph in row:" & vbNewLine &   TextBlockCanBeDefined & "no “Text Block Row” can be defined"
mess = mess & vbCrLf & "For the table paragraph in row:" & vbNewLine & noTextBlockCanBeDefined & "is no “Text Block Row” defined"
 If mess <> "" Then MsgBox mess


End Sub

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    尝试以下方法:

    For Each cell In rngcheck
        If IsEmpty(cell) Then
            ***j = cell.Address(0, 0) & vbNewLine***
            If cell.Offset(, 1).Value = "L" Then
                TextBlockCanBeDefined = TextBlockCanBeDefined & j & vbNewLine
                'For the table paragraph in row 7 is no “Text Block Row” defined
                'rngcheck.ClearContents
            ElseIf cell.Offset(, 1).Value = "T" Then
                noTextBlockCanBeDefined = noTextBlockCanBeDefined & j & vbNewLine
                'cell.Clear
            End If
            'mess = mess & vbCrLf & j & "is ok"
        End If
    Next cell
    
    mess = vbCrLf & "For the line paragraph in row:" & vbNewLine & TextBlockCanBeDefined & "no “Text Block Row” can be defined"
    mess = mess & vbCrLf & "For the table paragraph in row:" & vbNewLine & noTextBlockCanBeDefined & "is no “Text Block Row” defined"
    

    【讨论】:

    • 现在发布了。
    • 你删除了以下部分:If mess "" Then MsgBox mess.这部分是必要的。
    • 现在可以了,但是消息框:“对于行中的行段落:” & vbNewLine & TextBlockCanBeDefined & “不能定义“文本块行””重复两次
    • 嗨,也许我有一个解决方案:请编辑以下行:j = j & cell.Address(0, 0) & vbNewLine to j = cell.Address(0, 0) & vbNewLine跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 2016-08-10
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多