Copy Non Blank Cells From Range to Range

后端 未结 2 1052
感动是毒
感动是毒 2020-12-11 13:55

I wonder if you can help me with this:

Ranges B11:B251 & C11:C251 may or may not have some values. I want to be able to copy non blank cells from cell ranges M1

相关标签:
2条回答
  • 2020-12-11 14:02
    Sub Main()
        Dim i As Long
        For i = 11 To 251
            If Not IsEmpty(Range("M" & i)) Then _
                Range("B" & i) = Range("M" & i)
            If Not IsEmpty(Range("N" & i)) Then _
                Range("C" & i) = Range("N" & i)
        Next i
    End Sub
    

    this code will only copy non empty values from M&N columns to B&C

    0 讨论(0)
  • 2020-12-11 14:23

    This piece of code should do the trick:

    Sub CopyRangeToRange()
        Dim CpyFrom As Range
        Dim Cell As Range
    
        Set CpyFrom = ActiveSheet.Range("M11:N251")
    
        For Each Cell In CpyFrom
            If Cell.Value <> vbNullString Then
                Cell.Offset(0, -11).Value = Cell.Value
            End If
        Next Cell
    End Sub
    
    0 讨论(0)
提交回复
热议问题