excel vba 宏问题

关于程序出错PrivateSubCommandButton1_Click()Fori=1To10000IfCells(i,1)<Cells(i,2)ThenCells(i... 关于程序出错
Private Sub CommandButton1_Click()

For i = 1 To 10000
If Cells(i, 1) < Cells(i, 2) Then
Cells(i, 2).Select Selection.insert Shift:=xlDown

ElseIf Cells(i, 1) > Cells(i, 2) Then
Cells(i, 1).Select _
Selection.insert Shift:=xlDown _
else
End If
Next i
End Sub
这段宏有什么问题?我刚开始学习编程,很多不懂,大家多多指教
展开
 我来答
晋访7V
2009-06-28 · TA获得超过1398个赞
知道小有建树答主
回答量:717
采纳率:100%
帮助的人:548万
展开全部
这段宏中
Cells(i, 2).Select Selection.insert Shift:=xlDown
应当分成两句
Cells(i, 2).Select
Selection.insert Shift:=xlDown
还有
Cells(i, 1).Select _
Selection.insert Shift:=xlDown _
也是一样

主要问题还有
插入空单元格后,你的i变量值没有调整,按原有步长加1后,定位会是新插入的空单元格下的那个格,也就是你刚刚定位过的那个
zht0131
2009-06-28
知道答主
回答量:4
采纳率:0%
帮助的人:0
展开全部
Private Sub CommandButton1_Click()

For i = 1 To 10000
If Cells(i, 1) < Cells(i, 2) Then
Cells(i, 2).Insert Shift:=xlDown

ElseIf Cells(i, 1) > Cells(i, 2) Then
Cells(i, 1).Insert Shift:=xlDown
Else
End If
Next i
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式