2015-08-20 96 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