简体   繁体   English

Excel宏更改活动单元格

[英]Excel Macro to Change Active Cell

I have created a form in Excel. 我已经在Excel中创建了一个表单。 Based on how the user completes one cell, changes which cells they fill out next (for example: When filling out A10 if they answer "X" they will move to B1, if they answer "Y" they will move to B3.) 根据用户如何完成一个单元格,更改下一个要填写的单元格(例如:如果填写A10,如果回答“ X”,他们将移至B1,如果回答“ Y”,则将移至B3。)

In order to guide the user through the form, I created a complex set of conditional formatting rules which will "highlight"(background fill) the next cell they need to fill out. 为了指导用户完成表单,我创建了一组复杂的条件格式设置规则,这些规则将“突出显示”(背景填充)他们需要填写的下一个单元格。 Once they complete the cell the formatting on that cell goes away and switches to the next cell. 一旦他们完成了该单元格,该单元格上的格式就会消失并切换到下一个单元格。

I have the conditional formatting working exactly how I want. 我的条件格式完全符合我的要求。 My question is: Is there a way to have the active cell follow this same path. 我的问题是:是否有办法让活动单元遵循相同的路径。 Either by setting up the same formula rules that guide the conditional formatting or is there a way to have a macro auto set the active cell to the "highlighted" cell from the conditional formatting? 通过设置指导条件格式设置的相同公式规则,还是有一种方法可以使宏自动将活动单元格设置为条件格式中的“突出显示”单元格?

Try this: 尝试这个:

Private Sub Worksheet_Change(ByVal Target As Range)
    Const NEUTRAL = 16777215
    Dim r As Range
    For Each r In Cells.SpecialCells(xlCellTypeAllFormatConditions)
        If r.DisplayFormat.Interior.Color <> NEUTRAL Then
            r.Select
            Exit For
        End If
    Next
End Sub

Note: you can edit NEUTRAL at the top if non-highlighted cells have a different color than pure white. 注意:如果未突出显示的单元格的颜色与纯白色的颜色不同,则可以在顶部编辑NEUTRAL

Note: this assumes that the cell you want the selection to jump to is the only cell on the sheet that is highlighted with conditional formatting. 注意:这假定您要选择的单元格是工作表上唯一用条件格式突出显示的单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM