我正在Win 7上开展EXCEL 2010 vba。
我需要在一列中找到NULL为空的数据行。并将它们复制到同一工作表中的另一个范围。
Option Explicit
Sub find_null_entries()
Dim ActSheet As Worksheet
Dim myRange As Range
Dim null_counter As Integer
Dim res_rng As Range
null_counter = 0
Set ActSheet = ActiveSheet
Set myRange = Selection
Range("D1").Value = "NULL rows"
For Each c In myRange
If c.Value Is "NULL" Then
null_count = null_count + 1
res_rng // copy the data entry to another range in the same worksheet, e.g. column D
End If
Next c
End Sub
e.g。
item value
person1 NULL // find this row and then copy the **WHOLE** row to another range in the same worksheet
person2 18
更新
copy "person1 NULL" to another two columns
example: from A2:B2 to D2:E2
我有5000行数据,但可能有100行“NULL”。我需要找到它们并复制到toehr列。
任何帮助都将不胜感激。
答案 0 :(得分:1)
<强> UPD:强>
Sub find_null_entries()
Dim myRange As Range
Dim c As Range
Dim null_counter As Long
Set myRange = Intersect(Selection, ActiveSheet.UsedRange)
Range("D1").Value = "NULL rows"
For Each c In myRange
If c.Value Like "*NULL*" Then
null_counter = null_counter + 1
Range("D1").Offset(null_counter).Resize(, 2).Value = c.Offset(, -1).Resize(, 2).Value
End If
Next c
End Sub