vba if语句

[复制链接]
查看11 | 回复4 | 2018-5-7 18:27:10 | 显示全部楼层 |阅读模式
i = Worksheets("???").Range("c65536").End(xlUp).Row
For j = i To 1 Step -1
If Cells(j, 3).Value = Cells(j - 1, 3).Value And Cells(j, 6).Value = Cells(j - 1, 6).Value Then
Cells(j - 1, 8).Value = Cells(j - 1, 8).Value + Cells(j, 8).Value
Cells(j - 1, 9).Value = Cells(j - 1, 9).Value + Cells(j, 9).Value
Cells(j - 1, 11).Value = Cells(j - 1, 11).Value + Cells(j, 11).Value
Cells(j, 8) = ""
Cells(j, 9) = ""
Cells(j, 11) = ""
Else
Cells(j, 8).Value = Cells(j, 8).Value
Cells(j, 9).Value = Cells(j, 9).Value

Cells(j, 11).Value = Cells(j, 11).Value
End If
Next j
End With
End Sub
,可以运行但电脑提示if 语句语法错误
电脑提示if 的那行“应用程序定义的或对象定义的错误”

回复

使用道具 举报

千问 | 2018-5-7 18:27:10 | 显示全部楼层
VBA判断语句 1)If?Then?Else语句 IfconditionThen[statements][Elseelsestatements] 如1:IfA>B And C250Thenx=x-100 或者,可以使用块形式的语法: If condition Then [statements] [ElseIf condition-n Then [elseifstatements] ...[Else [elsestatements]] End If 如1: IfNumber < 10Then Digits = 1 ElseIfNumb
回复

使用道具 举报

千问 | 2018-5-7 18:27:10 | 显示全部楼层
最可能的原因是,因为变量 j 的值不合适,比如 j=0 或 j=1,就会造成如下对象引用的出错: Cells(j, 3)、Cells(j - 1, 3)、Cells(j - 1, 6) 也许把这句 For j = i To 1 Step -1改为: For j = i To 2 Step -1 就可以解决了。因为不了解
回复

使用道具 举报

千问 | 2018-5-7 18:27:10 | 显示全部楼层
我的观点与chenjin99类似:如果你的i=1,(无值,或仅一行的情况)那么下句 If Cells(j, 3).Value = Cells(j - 1, 3).Value And Cells(j, 6).Value = Cells(j - 1, 6).Value Then中的Cells(j - 1, 6),中值就为Cells(0, 6)而这样的单元
回复

使用道具 举报

千问 | 2018-5-7 18:27:10 | 显示全部楼层
Then应与If在同一行
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行