繁体   English   中英

颜色用户定义的选定单元格并将文本添加到 Excel VBA 中选择的最后一个单元格

[英]Colour User Defined selected cells and add text to last cell in selection in Excel VBA

我想在 Excel 中为用户定义的选择着色,然后在选择的最后一个单元格中添加一个文本条目。

到目前为止,我有选择但排序但在文本输入上挣扎。

Dim Cell As Object
Sheets("Jobs").Activate
For Each Cell In Selection
Cell.Interior.Color = RGB(255, 192, 0)
Next Cell

您可以在每个循环上设置一个范围 object ,这将在它完成时成为最后一个......

Dim Cell As Range, objLastCell As Range

Sheets("Jobs").Activate

For Each Cell In Selection
    Cell.Interior.Color = RGB(255, 192, 0)
    Set objLastCell = Cell
Next Cell

objLastCell.Value = InputBox("Enter some text and I'll throw it in cell " & objLastCell.Address & " ...", "Enter Text")

……反正是这样的。

此外,这假定最后一个单元格是最后一个选定的单元格,而不是选择中的最后一个(即右下角)单元格。

暂无
暂无

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

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