Vba 忽略空白单元格
我已经写了一个代码,它完全符合我的要求,只是它也改变了匹配空格的颜色。我想知道我可以添加什么到代码中,以便不标记空白单元格Vba 忽略空白单元格,vba,excel,Vba,Excel,我已经写了一个代码,它完全符合我的要求,只是它也改变了匹配空格的颜色。我想知道我可以添加什么到代码中,以便不标记空白单元格 beginrow = 2 First = 0 FirstLast = 0 Second = 0 SecondLast = 0 For z = 2 To finalrow If Cells(z, 9).Value = Cells(1 + z, 9).Value And Cells(z, 10).Value <> Cells(1 + z, 10).Valu
beginrow = 2
First = 0
FirstLast = 0
Second = 0
SecondLast = 0
For z = 2 To finalrow
If Cells(z, 9).Value = Cells(1 + z, 9).Value And Cells(z, 10).Value <> Cells(1 + z, 10).Value And Cells(z, 12).Value = Cells(1 + z, 12).Value Then
First = z
FirstLast = First + 1
End If
If Cells(z, 9).Value = Cells(1 + z, 9).Value And Cells(z, 12).Value <> Cells(1 + z, 12).Value Then
Second = z
SecondLast = Second + 1
endKnown = True
End If
If endKnown = True Then
For arownumber = beginrow To First 'need to find the rownumbers that we compare with
For change = 4 To 7
For smrownumber = FirstLast To Second 'need to find the rownumbers for comparing
For across = 4 To 7
CellA = Cells(arownumber, change)
CellB = Cells(smrownumber, across)
match = IIf(CellA = CellB, "yes", "no")
If match = "yes" Then
Cells(arownumber, change).Interior.ColorIndex = 3
Cells(smrownumber, across).Interior.ColorIndex = 3
End If
Next across
Next smrownumber
Next change
Next arownumber
endKnown = False
If SecondLast <> 0 Then
beginrow = SecondLast
End If
End If
Next z
beginrow=2
第一个=0
FirstLast=0
秒=0
SecondLast=0
对于z=2到最终箭头
如果单元格(z,9)。值=单元格(1+z,9)。值和单元格(z,10)。值单元格(1+z,10)。值和单元格(z,12)。值=单元格(1+z,12)。那么值
第一个=z
FirstLast=First+1
如果结束
如果单元格(z,9).Value=单元格(1+z,9).Value和单元格(z,12).Value单元格(1+z,12).Value然后
秒=z
SecondLast=Second+1
endKnown=True
如果结束
如果endKnown=True,则
对于arownumber=beginrow To First“需要查找与之比较的行号
对于更改=4到7
对于smrownumber=FirstLast To Second“需要查找行号进行比较
对于交叉=4到7
CellA=单元格(arownumber,更改)
CellB=单元格(smrownumber,跨行)
匹配=IIf(单元格A=单元格B,“是”、“否”)
如果match=“yes”,则
单元格(arownumber,change).Interior.ColorIndex=3
单元格(smrownumber,交叉)。Interior.ColorIndex=3
如果结束
下一个
下一个smrownumber
下一个变化
下一个号码
endKnown=False
如果最后一个为0,则
beginrow=第二个最后一个
如果结束
如果结束
下一个z
在更改单元格
对象的内部
属性的颜色索引
之前,必须检查是否有空内容
'If your cell isn't empty then change background color
If(Cells(arownumber, change).Value <> "") Then
Cells(arownumber, change).Interior.ColorIndex = 3
End If
'If your cell isn't empty then change background color
If(Cells(smrownumber, across).Value <> "") Then
Cells(smrownumber, across).Interior.ColorIndex = 3
End If
在更改
单元格
对象的内部
属性的颜色索引
之前,必须检查是否有空内容
'If your cell isn't empty then change background color
If(Cells(arownumber, change).Value <> "") Then
Cells(arownumber, change).Interior.ColorIndex = 3
End If
'If your cell isn't empty then change background color
If(Cells(smrownumber, across).Value <> "") Then
Cells(smrownumber, across).Interior.ColorIndex = 3
End If
你是说像这样
match = IIf((CellA = CellB) And (CellA <> ""), "yes", "no")
你是说像这样
match = IIf((CellA = CellB) And (CellA <> ""), "yes", "no")
我可能错了,但我猜用户指的是
match=IIf(CellA=CellB,“yes”,“no”)
:@SiddharthRout实际上你可能是对的。两种方法都是正确的。你选择不匹配空单元格,而我只是在更改背景之前检查它是否为空:)我猜这两种解决方案对他都有效。如果其中一个是空的,那么如果你单独做,它不会改变它的颜色吗?我的理解是,如果它们都匹配,并且不是空的,或者根本没有颜色,就给它们上色。。。无论如何,让我们看看OP想要什么。。。就像我说的,我可能错了:我使用了这个解决方案,但另一个似乎也同样有效。@SiddharthRout如果只有一个是空的,那么它们就不匹配了,所以我们甚至不需要检查条件,对吗?我可能错了,但我猜用户指的是match=IIf(CellA=CellB,“是”,“否”)
:)@SiddharthRout实际上你可能是对的。两种方法都是正确的。你选择不匹配空单元格,而我只是在更改背景之前检查它是否为空:)我猜这两种解决方案对他都有效。如果其中一个是空的,那么如果你单独做,它不会改变它的颜色吗?我的理解是,如果它们都匹配,并且不是空的,或者根本没有颜色,就给它们上色。。。无论如何,让我们看看OP想要什么。。。就像我说的,我可能错了:我使用了这个解决方案,但另一个似乎也同样有效。@SiddharthRout如果只有一个是空的,那么它们就不匹配了,所以我们甚至不需要经历这个条件,对吗?