繁体   English   中英

VBA在Excel上删除无颜色的单元格和相邻单元格

[英]VBA on Excel to delete cells with no color and neighbour cells

因此,我尝试找出一种使用VBA进行以下技巧的方法:

假设我们有一个巨大的Excel文件。

C500有一些文字。 M500有一个值,可以填充颜色,也可以只是带有数字的默认白色单元格。 我要实现的是在M500没有颜色填充时删除C500和M500。

我知道这是一个简单的任务,至少看起来像这样,而且我知道只需几行代码就可以解决。 我仍然无法通过搜索来在Google上找到我所需要的内容或堆栈溢出,这可能是由于我的搜索能力很差或因为我想做的事情很具体。

我们将不胜感激任何帮助,我将非常乐意看到任何类似的宏网站都可以用作参考。 抱歉,这个问题已经回答。

我正在重写此答案,因为需求需要遍历为范围中的每个单元格以及单元格的其他值定义的任何FormatCondition。 例如,可以在此处找到一种整洁的方法。 基本上,它包括:

For X = 1 To Cell.FormatConditions.Count
    With Cell.FormatConditions(X)
      If .Type = xlCellValue Then
      ...
      If CellInterior Then
          DisplayedColor = IIf(ReturnColorIndex, Cell.Interior.ColorIndex, Cell.Interior.Color)
        Else
          DisplayedColor = IIf(ReturnColorIndex, Cell.Font.ColorIndex, Cell.Font.Color)

它将探索以不同方式定义填充颜色的单元格。

所以你应该遍历整个范围

Dim rng As Range, cell As Range
Set rng = Range("M500:M550")
For Each cell In rng
   rem check the filling with the method in the link
   rem if it's the colorindex you want
   rem cell.Value = ''
   rem Also, get the row number and delete content of range ("C5XX")
Next cell

暂无
暂无

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

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