如何跳过列中的空单元格?

我的列A的值是像kat1 kat2空kat3我希望程序本质上跳过空单元格,并使用kat3作为单元格设置最后一行(lrow)。 我正在使用的代码如下所示。 以下是修改后的代码:

Private Sub txt_BPName1_Exit(ByVal cancel As MSForms.ReturnBoolean) Dim ws As Worksheet Dim Lrow As Long Dim c As Range, rng As Range Set ws = ThisWorkbook.Sheets("Sheet1") With ws Lrow = .Range("A" & .Rows.Count).End(xlUp).row 'Lrow = .Range("A" & .Rows.Count, 1).End(xlUp).Select 'Lrow = .Range("A65536").End(xlUp).row + 1 Set rng = .Range("A2:A" & Lrow) End With For Each c In rng If c.Value = txt_BPName1 And c.Value <> "" Then MsgBox "Cell " & c.Address & " Duplicate Found." cancel = True Exit Sub End If Next MsgBox ("Base Product is not duplicate,Ok to Add") Cells(Lrow + 1, 1).Value = txt_BPName1.Text txt_BPName1.Text = "" ActiveCell.Offset(1, 0).Select End Sub 

该值正在进入空单元格,而不是下面的一个。

只需在循环中添加if语句

 For Each c In rng If not "" = c.Value Then