![](/img/trans.png)
[英]VBA excel - delete entire row based on the outcome of statement based on two values in two columns
[英]VBA Delete row based on 2 columns
我有一些VBA代碼,如果列中的單元格具有紅色文本,它將刪除整行
Dim Cell As Range
For Each Cell In Intersect(Columns("L"), ActiveSheet.UsedRange)
If Cell.DisplayFormat.Font.ColorIndex = 3 Then Cell.Value = "#N/A"
Next
On Error GoTo NoRedText
Columns("L").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
NoRedText:
我想擴展此代碼,使其也包含在單元格中包含“ Y”值的另一列。
L列包含紅色文本字符串
P列包含“ Y”文本字符串
因此,如果L列中的文本為紅色並且P列中的文本等於“ Y”,則應刪除整行
為此,我需要添加什么代碼?
謝謝
您的Cell
變量引用了一個范圍及其所有屬性。
Offset
屬性
返回一個Range對象,該對象表示一個偏離指定范圍的范圍。 ( https://msdn.microsoft.com/zh-cn/library/office/ff840060.aspx )
使用此知識,您可以告訴您的代碼查看由四列偏移的范圍:
If Cell.DisplayFormat.Font.ColorIndex = 3 AND Cell.Offset(,4)="Y" Then Cell.Value = "#N/A"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.