Copy and Paste certain values

Plastik808

New Member
Joined
Aug 15, 2011
Messages
11
Hi,

As you will probably gather from my simple questiom, I am new to VBA and am trying to copy certain values (less than 5) in a certain range to another column in the worksheet. Column A has a list of different numbers and i am trying to copy on those numbers less than 5 and place them in C

Private Sub CommandButton1_Click()
Dim example As Integer, i As Integer
example = 0
For i = 1 To 99
If Cells(i, 1).Value <5 Then Copy
Next i
Range("C1").Value.Paste

End Sub


What am i doing wrong please?


Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try

Code:
Private Sub CommandButton1_Click()
Dim example As Integer, i As Integer
example = 0
For i = 1 To 99
    If Cells(i, 1).Value < 5 Then Cells(i, 1).Copy Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1)
Next i
End Sub
 
Upvote 0
Try this
Code:
Sub Test()
Dim LR As Long
Dim LR2 As Long
LR = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To LR
If Cells(i, 1) < 5 Then
   LR2 = Cells(Rows.Count, 3).End(xlUp).Row
   Cells(i, 1).Copy Cells(LR2 + 1, 3)
End If
Next i
End Sub

lenze
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top