简体   繁体   中英

copy data rows with NULL column to another range in the same worksheet

选择NULL行,然后复制 I am working on EXCEL 2010 vba on Win 7.

I need to find data rows with NULL in one column. And copy them to another range in the same worksheet.

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

eg

  item     value
  person1  NULL   // find this row and then copy the **WHOLE** row to another range in the same worksheet
  person2  18

UPDATE

  copy "person1  NULL" to another two columns  
  example: from A2:B2  to  D2:E2 

I have 5000 rows of data but maybe have 100 rows with "NULL". I need to find them and copy to toehr columns.

Any help would be appreciated .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM