gpt4 book ai didi

vba - 跳过有颜色的单元格

转载 作者:行者123 更新时间:2023-12-02 17:49:29 25 4
gpt4 key购买 nike

我有一个循环,我想跳过有颜色的单元格。

For i = 1 To Count
Do While ActiveCell.Offset(0, i).Interior.ColorIndex = 15
i = i + 1: Count = Count + 1
Loop

With ActiveCell.Offset(0, i).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
Next i

它可以工作,但是初始计数变量没有更新。因此,如果我有 10还有2跳过,i值增加并且有效,仍然是 count保持在10 ,即使变量显示 12 。看起来好像增加了 count变量不会增加 For环形。我不能接受1远离i变量,因为这会导致 activecell.offset受到影响。

最佳答案

为什么要使用.Offset?这就是你正在尝试的吗?这样您也可以跳过彩色单元格。

Dim col As Long, rw As Long, i As Long

col = ActiveCell.Column
rw = ActiveCell.Row

For i = 1 To Count
With Cells(rw, col + i)
If .Interior.ColorIndex <> 15 Then
With .Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = -0.249977111117893
.PatternTintAndShade = 0
End With
End If
End With
Next i

关于vba - 跳过有颜色的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38893472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com