宏脚本Excel,用NULLS填充空白,错误400

时间:2010-12-21 02:02:48

标签: excel-vba vba excel

我想要做的就是在空白的单元格中填入NULL。

源代码:

Sub fillNULLs()

Dim count As Integer
count = 0

Dim col As Integer
col = 2

While count < 23403

If (Cells(count, col) = "") Then

Cells(count, col) = "Null"

End If

count = count + 1

Wend

End Sub

我运行宏,我得到一个400和一个好的按钮。任何人都可以发现问题

2 个答案:

答案 0 :(得分:1)

Sub fillNULLs()
Dim a, b As Range

Set a = Range("B1:B23402")
For Each b In a
   If (Trim(b.Value) = "") Then b = Null
Next b

End Sub  

修改

检查它是否正在做它必须做的事情

Sub fillNULLs()
Dim a, b As Range

Set a = Range("B1:B23402")
For Each b In a
   If (Trim(b.Value) = "") Then b = "Null"
Next b  

End Sub  

您将在修改后的值中看到“Null”。

答案 1 :(得分:0)

我想在while循环

之前,计数应该是1
相关问题