如果不是Isempty返回“”值,但继续下一个语句
问题描述:
此代码检查列G,如果它的值是“Test”,则在E列获取相应的值并将其粘贴到下一行。如果不是Isempty返回“”值,但继续下一个语句
Sub FindOpcode_Placepart()
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim destCol_part As Integer, destRow As Integer
Dim currentRowValue As String
Dim destRowValue As String
sourceCol_opcde = 7 ' find last row in column E
rowCount = Cells(Rows.Count, sourceCol_opcde).End(xlUp).Row
destCol_part = 5
destRow = Cells(Rows.Count, sourceCol_opcde).End(xlUp).Row
'for every row, find the Opcode
For currentRow = 1 To rowCount
If Cells(currentRow, sourceCol_opcde).Value = "Test" Then
destRowValue = Cells(currentRow, destCol_part).Text
If Not IsEmpty(destRowValue) Then ' this code returns "" value but proceeds with the next statement.
destRow = currentRow + 1
While Cells(destRow, sourceCol_opcde).Value = "Use-Limit"
Cells(destRow, destCol_part).Value = destRowValue
destRow = destRow + 1
Wend
End If
End If
Next
End Sub
答
IsEmpty不是一个检查,看看如果单元格的值,这是一个检查,看看是否变量已初始化。
'Note lack of Option Explicit.
Private Sub Example()
Debug.Print IsEmpty(foo) 'True.
foo = 42
Debug.Print IsEmpty(foo) 'False.
End Sub
在从问题的代码,destRowValue
被初始化Dim destRowValue As String
。要检查电池是否具有价值或没有,你需要测试针对vbNullString
...
If Cells(currentRow, destCol_part).Text = vbNullString Then
...不过请记住,如果你有一个函数的目标小区的可能性也可能想测试ISERROR:
If Not IsError(Cells(currentRow, destCol_part)) And _
Cells(currentRow, destCol_part).Text = vbNullString Then
因为......
Cells(1, 1).Value = "=SomefunctionThatDoesntExist"
Debug.Print Cells(1, 1).Text 'Returns "#NAME?"
答
更换
If Not IsEmpty(destRowValue) Then
与
If destRowValue <> "" Then
+0
它的作品!谢谢!请你再解释一下? –
+0
感谢您的回复。如果它解决了您的解决方案,请将其标记为答案。 –
感谢您的解释。 :)我很喜欢这个网站! –