Vba 跳过已着色的单元格

Vba 跳过已着色的单元格,vba,excel,Vba,Excel,我有一个循环,我想跳过有颜色的单元格 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 = xlAut

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

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
值增加并且有效,那么
计数仍然保持在
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
Dim col As Long,rw As Long,i As Long
col=ActiveCell.Column
rw=ActiveCell.Row
对于i=1进行计数
带单元格(rw、col+i)
如果.Interior.ColorIndex 15,则
带.内饰
.Pattern=xlSolid
.PatternColorIndex=xlAutomatic
.ThemeColor=xlThemeColorAccent3
.TintAndShade=-0.249977111117893
.PatternTintAndShade=0
以
如果结束
以
接下来我

可能代码效率很低,但行数不多。记住,该列有一个日期,如果该列是星期六或星期日,即灰色,则代码应跳过这些单元格,但不能从整个计数器中减去它们

If Not IsEmpty(y.Value) And IsNumeric(y.Value) And y.Value >= 7.5 Then
With ActiveCell.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = -0.249977111117893
    .PatternTintAndShade = 0
End With
Col = y.Value - 7.5
Col = Col / 7.5


Count = Left(Col, Len(Col) - InStr(1, Col, ".") + 1)
y = 0
For i = 1 To Count


Do While ActiveCell.Offset(0, i).Interior.ColorIndex = 15
ActiveCell.Offset(0, 1).Select
y = y + 1
Loop
With ActiveCell.Offset(0, i).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent3
    .TintAndShade = -0.249977111117893
    .PatternTintAndShade = 0
End With
Next i

ActiveCell.Offset(0, -y).Select
ActiveCell.Offset(0, i + y).Select
Do While ActiveCell.Interior.ColorIndex = 15
ActiveCell.Offset(0, 1).Select
Loop
Co = Right(Col, Len(Col) - InStr(1, Col, "."))
If Len(Co) > 2 Then
Co = Mid(Co, 1, InStr(1, Col, ".")) & "." & Mid(Co, InStr(1, Col, ".") + 1, Len(Co) - InStr(1, Col, "."))
End If
If Co = 0 Then
ElseIf Co >= 0.1 And Co <= 25 Then
With ActiveCell.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -4.99893185216834E-02
    .PatternTintAndShade = 0
End With
ElseIf Co >= 26 And Co <= 49 Then
With ActiveCell.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent6
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
ElseIf Co >= 5 And Co <= 74 Then
With ActiveCell.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorLight2
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With
ElseIf Co >= 75 And Co <= 99 Then
With ActiveCell.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -4.99893185216834E-02
    .PatternTintAndShade = 0
End With
End If
End If

Next y
如果不是IsEmpty(y.Value)和IsNumeric(y.Value)且y.Value>=7.5,则
带ActiveCell。内部
.Pattern=xlSolid
.PatternColorIndex=xlAutomatic
.ThemeColor=xlThemeColorAccent3
.TintAndShade=-0.249977111117893
.PatternTintAndShade=0
以
Col=y.值-7.5
Col=Col/7.5
计数=左(列,长(列)-仪表(1,列,“.”+1)
y=0
对于i=1进行计数
当ActiveCell.Offset(0,i.Interior.ColorIndex=15时执行此操作
ActiveCell.Offset(0,1)。选择
y=y+1
环
带ActiveCell.Offset(0,i).内部
.Pattern=xlSolid
.PatternColorIndex=xlAutomatic
.ThemeColor=xlThemeColorAccent3
.TintAndShade=-0.249977111117893
.PatternTintAndShade=0
以
接下来我
ActiveCell.Offset(0,-y)。选择
ActiveCell.Offset(0,i+y)。选择
当ActiveCell.Interior.ColorIndex=15时执行此操作
ActiveCell.Offset(0,1)。选择
环
Co=右(列,长(列)-仪表(1,列,“.”)
如果Len(Co)>2,则
Co=Mid(Co,1,仪表(1,柱,“.”)和“&&Mid(Co,仪表(1,柱,“”)+1,透镜(Co)-仪表(1,柱,“.”)
如果结束
如果Co=0,则

ElseIf Co>=0.1,Co=26,Co=5,Co=75,Co我说的对吗?您试图找到颜色索引为15的最后一个单元格,然后更改下一个单元格的颜色?for循环已预编译,启动后无法更改。你需要使用一个While循环来增加Siddhart的可能副本,就像往常一样,你提供了一个很好的答案!我必须保留偏移量的原因,如果因为可以有一个余数,它需要使用不同的颜色。从本质上说,我正在创建一个计划者,它将数字除以7.5(一个工作日),然后用除法的答案进行抵消,而剩余部分将被着色为不同的颜色。请参阅下面我复杂的答案。我确信,您仍然不需要
.Offset
:)