VBA消息框来处理筛选的数据select

我试图创build一个macros,我可以在使用自动筛选器的工作表上运行。 在理想的世界里,我的macros应该显示一个消息框,给我三个select:

1)在第一个可见行(忽略标题)上运行一组特定的VBA指令(在下面的代码中用于给单元格B2着色),然后移动到下一个可见行并再次显示消息框。
2)跳过这一行,find下一个可见行并再次显示消息框。
3)退出macros。

我有下面的macros的裸骨,但是我觉得我错过了一些聪明的方式,在按下前两个button后再次显示消息框。 此外,我不相信我的代码结束macros观。

仅供参考:消息框的原因,而不是一个扁平的循环macros是filter经常改变,我正在寻求减less需要重写基于必要的filter的代码。

Sub Msg_exe() Dim Option_Menu As Integer Dim strMsg As String Dim strTitle As String Range("B2").Select strMsg = "Continue with this row" strTitle = "Alert" Option_Menu = MsgBox(strMsg, vbYesNoCancel + vbQuestion, strTitle) Select Case Option_Menu Case 6 'code to colour the cell goes here Selection.Font.ColorIndex = 25 Selection.Interior.ColorIndex = 33 ActiveCell.Offset(1, 0).Activate Do While ActiveCell.EntireRow.Hidden = True ActiveCell.Offset(1, 0).Activate Loop 'I need some code to show the message box again ready for the next row Case 7 'code to skip to the next visable line goes here ActiveCell.Offset(1, 0).Activate Do While ActiveCell.EntireRow.Hidden = True ActiveCell.Offset(1, 0).Activate Loop 'I need some code to show the message box again ready for the next row Case 2 'the code to end the macro goes here (I hope this is correct) End End Select End Sub 

你可以循环行,从你决定的行开始,并确定是否需要计算(我还没有testing,所以请检查这匹配你的要求第一):

 Sub Msg_exe() Dim cur_row as long Dim Option_Menu As Integer Dim strMsg As String Dim strTitle As String For cur_row = 2 to Range("A65000").End(xlUp).Row 'Modify this row referenced to suit if not Range("B" & cur_row).EntireRow.Hidden then Range("B" & cur_row).Select strMsg = "Continue with this row" strTitle = "Alert" Option_Menu = MsgBox(strMsg, vbYesNoCancel + vbQuestion, strTitle) Select Case Option_Menu Case 6 'code to colour the cell goes here Selection.Font.ColorIndex = 25 Selection.Interior.ColorIndex = 33 Case 7 'code to skip to the next visible line goes here Case 2 'the code to end the macro goes here (I hope this is correct) Exit Sub End Select End If Next End Sub