Forum Discussion
Ajit Karode
Apr 03, 2018Copper Contributor
excel vba code to copy and paste only few cell of row which match criteria
In excel vba what to type which will copy only need cell of row which is matching criteria
Matt Mickle
Apr 03, 2018Bronze Contributor
Please use this example to copy a single cell:
Sub Test()
Dim X As Integer
For X = 1 To 10
'Copy a cell in Row 5 between columns A and J i.e. 1 To 10
'if it meets the proper criteria
If ActiveSheet.Cells(5, X) = "Copy Me" Then
ActiveSheet.Cells(5, X).Copy
End If
Next
End Sub
Use this example to copy multiple cells:
Sub Test2()
Dim X As Integer
Dim Rng As Range
For X = 1 To 10
'Copy multiple cells in Row 5 between columns A and J i.e. 1 To 10
'if it meets the proper criteria
If ActiveSheet.Cells(5, X) = "Copy Me" Then
If Not Rng Is Nothing Then
Set Rng = Union(Rng, ActiveSheet.Cells(5, X))
Else
Set Rng = ActiveSheet.Cells(5, X)
End If
End If
Next
Rng.Copy
End Sub