vba编程函数卡住(vba编程函数大全)

2023-12-19 12:52:30 数码极客 bianji01

 

在excel中,用vba编程,写了代码没有运行按钮点不了

private sub commandbutton1_click()dim i as integerdim j as integeri = 6with sheet1do while cells(i, 1) > 135 or cells(i, 1) < 120for j = i + 1 to i + 7 step 1if cells(j, 1) > cells(i, 1) thentextbox1 = i - 5textbox2 = cells(i - 5, 1)end ifnext j??i = i + 1 if i > 1000 then exit doloopend withend sub请见上面三处修改:i = 6 ,否则cells(i-5,1)中会出现第0行,报错;两个do 合并;do 中增加 i = i + 1否则相当于没循环;并增加一判断语句,否则不退出循环。其实代码应该写为:private sub commandbutton1_click()dim i as integerdim j as integerwith sheet1for i = 6 to range("a65000").end(xlup).rowdo while cells(i, 1) > 135 or cells(i, 1) < 120for j = i + 1 to i + 7 step 1if cells(j, 1) > cells(i, 1) thenTeXtbox1 = i - 5textbox2 = cells(i - 5, 1)end iFnext jnext iend withend sub

VBA代码执行被中断的问题

声明:易趣百科所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系315127732@qq.com
广告位招租
横幅广告