简体   繁体   English

Excel VBA使用当前单元格选择

[英]Excel VBA working with current cell selection

Sorry if this is a dumb question but still fairly new to VBA. 抱歉,这是一个愚蠢的问题,但对于VBA来说还是一个新手。

I'm building a daily schedule sheet, and as part of it want to be able to color code high and low priority appointments. 我正在建立一个日程安排表,并且其中一部分是希望能够对高优先级和低优先级约会进行颜色编码。 Rather than having to manually adjust the color and bold each one, I want to run a macro with a shortcut key to modify the cells I've selected. 无需手动调整颜色和加粗每个颜色,我想使用快捷键来运行宏来修改所选的单元格。

I have the color/bold part figured out, but am having trouble telling it to apply the changes the cells I have selected. 我已经弄清楚了颜色/粗体部分,但是很难告诉它应用我选择的单元格的更改。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Sorry, the code is- 抱歉,代码是-

Sub HighPriority() 

HighPriority Macro

    Range("AE27:AP27").Font.Color = RGB(255, 0, 0)
    Range("AE27:AP27").Font.Bold = True
End Sub

So instead of it always editing AE27:AP27, I would want it to apply the changes to whichever cells I have selected. 因此,我希望它不将其始终编辑AE27:AP27,而是将更改应用于所选的任何单元格。

After Select ing your cells, run something like: 选择单元格后,运行类似以下内容的命令:

Sub ColorMe()
    With Selection
        .Interior.ColorIndex = 27
        .Font.Bold = True
    End With
End Sub

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

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