如何识别合并的单元格是否为空并显示弹出消息

时间:2019-06-19 01:53:32

标签: excel vba

我需要显示一条弹出消息,指示根据每一列的表中缺少某些信息,例如如果A列中的一个单元格为空,则弹出消息将显示“请在A列中填写缺失值”,“请在B列中填写缺失值” ...

Table with merged cells

LastRow = sht.Cells(sht.Rows.Count, StartCell.Column).End(xlUp).Row
LastColumn = sht.Cells(StartCell.Row, sht.Columns.Count).End(xlToLeft).Column
sht.Range(StartCell, sht.Cells(LastRow, LastColumn)).Select

For Each Cell In Selection
For Row = 1 To LastRow
    If Cells(Row, 1).Value = "" Then
        if isempty(Cells(Row,1).mergearea().Value = true
            MsgBox "Please fill in the code"
    End If

    If Cells(Row, 2).Value = "" Then
        MsgBox "Please fill in the description" & Row
    End If

    If Cells(Row, 8).Value = "" Then
        MsgBox "Please fill in the discounting %" & Row

            ElseIf Cells(Row, 8).Value <> ">36%" Then
            Cells(Row, 8).Interior.ColorIndex = 4
    End If
Next Row

我应该用于选择的每个单元格还是下一个循环? 此代码将用作模板,这意味着每次列出的行数或行数都不同,具体取决于列出了多少“代码”项(列A),代码的前3行是否足以找出非空单元格的最后一行?

执行代码时,弹出消息总是比实际的空单元格数量更多。似乎我无法确定合并的单元格是否为空。

最后,我还需要查看折扣列中的值是否单元格内的值> 36%,如果是,则整行都突出显示。我该如何编码?非常感谢大家!

0 个答案:

没有答案