excel vba运行错误424:要求对象。 求教!!
Subcmpprice()Dimi,jAsIntegerDimrng,rng1AsRange'i<=2627Fori=2To5j=i+1IfCells(i,"C")=Ce...
Sub cmpprice()
Dim i, j As Integer
Dim rng, rng1 As Range
' i<=2627
For i = 2 To 5
j = i + 1
If Cells(i, "C") = Cells(j, "C") Then
rng.Value = Cells(i, "O")
rng1.Value = Cells(j, "O")
rng.Interior.Color = RGB(255, 0, 0)
rng1.Interior.Color = RGB(255, 0, 0)
End If
Next
End Sub 展开
Dim i, j As Integer
Dim rng, rng1 As Range
' i<=2627
For i = 2 To 5
j = i + 1
If Cells(i, "C") = Cells(j, "C") Then
rng.Value = Cells(i, "O")
rng1.Value = Cells(j, "O")
rng.Interior.Color = RGB(255, 0, 0)
rng1.Interior.Color = RGB(255, 0, 0)
End If
Next
End Sub 展开
2个回答
展开全部
cells() 应该是只允许数字吧,你把 ‘C’ 改成3; ‘O’改成15 试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接说你要什么效果
追问
比较两个单元格中内容,如果内容相同,将这两个的单元格显示红色
追答
Sub cmpprice()
Dim i As Integer, j As Integer '这里一定要两个变量都写上类型,否则不写的就是变体
For i = 2 To 5
j = i + 1
If Cells(i, "C") = Cells(j, "C") Then
Cells(i, "O").Interior.Color = vbRed
Cells(j, "O").Interior.Color = vbRed
End If
Next
End Sub
多看些基础的,定义RNG 为range类型后,要用
SET rng = Cells(i, "O")
SET RNG1=CELLS(J,"O")
这样才可以把变量当单元格。
另外定义要这样,
Dim rng as range , rng1 As Range
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |