如果在excel VBA中判断A列中的空白单元格,遇到后就终止程序 用VBA语句在EXCEL中编写,在没有选定A列中空白单元格就...
\u5982\u679c\u5728excel VBA\u4e2d\u5224\u65adA\u5217\u4e2d\u7684\u7a7a\u767d\u5355\u5143\u683c\uff0c\u9047\u5230\u540e\u5c31\u7ec8\u6b62\u7a0b\u5e8f\uff1ffor i = 1 to range("A65536").end(xlup).row()
\u5b9a\u4e49\u8fd9\u6837\u4e00\u4e2a\u53d8\u91cfi
\u5bf9i\u8fdb\u884c\u5faa\u73af\u5c31\u884c\u4e86\u3002
\u8fd9\u662f2003\u7684\u4ee3\u7801\uff0c2007\u53ca\u4ee5\u4e0a\u7684\uff0c\u628a65536\u4fee\u6539\u4e3a
1048576
\u4ec0\u4e48\u610f\u601d\uff1f
if selection.column= 1 and selection "" then msgbox "" :exit sub
Sub 检查空单元格()
Dim rng As Range, arr()
For Each rng In Range("A1:A30")
If rng = "" Then
N = N + 1
ReDim Preserve arr(1 To N)
arr(N) = rng.Address(0, 0)
End If
Next
MsgBox "A1:A30有" & N & "个空单元格," & vbCrLf & "分别是:" & Join(arr, ",")
End Sub
Sub 检查空格()
Dim rng As Range, arr()
For Each rng In Range("A1:A30")
If InStr(rng, " ") <> 0 Then
N = N + 1
ReDim Preserve arr(1 To N)
arr(N) = rng.Address(0, 0)
End If
Next
MsgBox "A1:A30包含空格的单元格有" & N & "个," & vbCrLf & "分别是:" & Join(arr, ",")
End Sub
for i = 1 to range("A65536").end(xlup).row()
定义这样一个变量i
对i进行循环就行了。
这是2003的代码,2007及以上的,把65536修改为
1048576
肯定是循环
其中假设一个if
if cells(i,1)="" then ' cells(i,1)表示的是a列
exit for '退出循环
else
你要执行的语句
endif
看是否适用
if cells(1,i).value<>0 then
exit sub
end if
a1.select
i=0
tz=ture
do while tz
if offsetcell(i,0)="" then
tz=false
else
msgbox offsetcell(i,0)
i=i+1
endif
loop
扩展阅读:excel vba实例800下载 ... vba入门 ... excel vba入门 ... excel vba论坛 ... excel vba图表 ... excel vba教程完整版 ... excel vba范例大全 ... excel vba经典案例 ... excel vba怎么打开 ...