我试图在迭代所有单元格后只打印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
答案 0 :(得分:0)
尝试以下方法:
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"