简体   繁体   English

如何清除A列以外的行的内容?

[英]How to clear content of rows except column A?

I have a macro which removes the content of the entire row with cells in light yellow in my selection (in my macro Range("B1:B3000")).我有一个宏,它在我的选择(在我的宏范围(“B1:B3000”)中)删除了整行的内容,并带有淡黄色的单元格。

在此处输入图片说明

My macro works but I would like to not remove the content of column A.我的宏有效,但我不想删除 A 列的内容。

I guess I should modify the line: rColored.EntireRow.ClearContents我想我应该修改这一行: rColored.EntireRow.ClearContents

Sub SelectColoredCellsVariantremovecelllightyellow()
    Dim rCell As Range
    Dim lColor As Long
    Dim rColored As Range
    Dim myselection As Range
    Set myselection = Range("B1:B3000")
    lColor = 10092543
    Set rColored = Nothing
    For Each rCell In myselection
        If rCell.Interior.Color = lColor Then
            If rColored Is Nothing Then
                Set rColored = rCell
            Else
                Set rColored = Union(rColored, rCell)
            End If
        End If
    Next
    rColored.EntireRow.ClearContents
    Set rCell = Nothing
    Set rColored = Nothing
End Sub

Here you can use Intersect to restrict the range to be cleared:这里可以使用Intersect来限制要清除的范围:

Replace代替

rColored.EntireRow.ClearContents

with

If Not rColored Is Nothing Then
    Intersect(rColored.EntireRow, Columns("B:AB")).ClearContents
End If

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

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