[英]Excel VBA to color only certain cells in a selected row
我正在尋找一個Excel VBA
代碼,它只會為任何給定的用戶選擇的行( cells A to P
)中的某些單元格着色,例如,而不是整行,它也為我的表格之外沒有數據的單元格着色。
用戶需要每天查看一個列表,並確定某條線路是否應該標記為綠色或橙色,例如,以便以后跟進。
目前我使用這個:
Selection.EntireRow.Select
With Selection.Interior
.Color = 49407
但如前所述,它還為我的數據范圍之外的單元格着色,我只希望范圍( A to P
)內的單元格着色。
您可以使用相交功能
Set RangeFixed= Range("A:P")
Application.Intersect(Selection.EntireRow,RangeFixed).Select
With Selection.Interior
.Color = 49407
基於這個答案
建議您盡量遠離Selection
,但如果您必須擁有它,請使用以下代碼:
Dim Rng As Range
Set Rng = Selection
Range(Cells(Rng.Row, "A"), Cells(Rng.Row, "P")).Interior.Color = 49407
“我們可以使用 activecell 對象為選定行的一部分着色
Dim i as integer
i=activecell.row
Range(cells(i,1),cells(i,16)).interior.color=49407
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.