2015-08-20 97 views
0

我有一个宏检查任何空白单元格的范围,然后运行第二个宏。目前,如果找到一个空白单元格,用户会收到一条消息,提醒他们空白单元格,并且宏结束。Excel VBA中断每个选择单元

我希望能够在结束宏之前选择空白单元格,以便用户知道在哪里找到它。

Dim e As Range 
Set e = Range("A2", Range("A1000").End(xlUp)) 

For Each Cell In e 
    If IsEmpty(Cell) Then 
     ActiveCell.Select 
     MsgBox ("Please remove empty row") 
     Cancel = True 
     Application.StatusBar = vbNullString 
     Exit Sub 
    End If 
Next 

是否有一个选择器会将空单元保持为活动状态?

回答

4

ActiveCell.Select替换为Cell.Select

0

试试这个....

Sub test() 
Dim e As Range 
Set e = Range("A2", Range("A1000").End(xlUp)) 

For Each Cell In e 
    If IsEmpty(Cell) Then 
     Cell.Select 
     MsgBox ("Please remove empty row") 

     Exit Sub 
    End If 
Next 


End Sub