copy paste with conditions

handrianomanana

New Member
Joined
May 28, 2010
Messages
3
Hi there,

I'm new with VBA and walk through old post but can work it out myself, I need more practices.

I want to copy values from one sheet to another if condition is met.

I have a list on one column on sheet1 and another list on other column in sheet2(they might not be the same), anytime the value on sheet2 equals one of the list value on sheet1, then a corresponding cell value on sheet1 should be paste on another cell in sheet2 of the same row.

thanks in advance
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi handrianomanana,

I'm new here too. Perhaps try something like this:-
Code:
For x=1 to y
if worksheets(1).cells(x,1)=worksheets(2).cells(x,1) Then
worksheets(2).cells(x,2)=worksheets(1).cells(x,1)
end if
next y
 
Upvote 0
I used this and get incompatible type

Sub Copy_value()
Dim d
d = ActiveSheet.UsedRange.Rows
For Each d In Worksheets("Feuil2").Rows
If Worksheets("Feuil2").Cells(d, 5) = Worksheets("Feuil1").Cells(d, 2) Then
Worksheets("Feuil1").Cells(d, 17).Copy = Worksheets("Feuil2").Cells(d, 12).Paste
End If
Next d
End Sub
 
Upvote 0
I was trying to 'paste' some stuff yesterday and kept getting error messages. vba didn't like 'paste' on it's own as a method. When I used 'PasteSpecial' it seemed to do the trick.
 
Upvote 0
Another couple of things to consider:-

1. How many rows have you got? If you've declared d as an integer and you've got over 32,000 rows then you may have to re-declare d as long.

2. Have you checked that the column of data in Feuil1 is formatted in the same way as the data in Feuil2?
 
Upvote 0
Hi, I didn't get any feedback so I worked out this code myself but it doesn't work

Sub copy_withconditions()
'
'Dim dernLigne, i,j
dernLigne = ActiveSheet.UsedRange.Row + ActiveSheet.UsedRange.Count - 1
Application.ScreenUpdating = False
For i = dernLigne To 1 Step -1
If Worksheets(2).Range("E" & i) = Worksheets(1).Range("B" & j) Then
Worksheets(1).Range("Q" & j).Copy Destination:=Worksheets(2).Range("L" & i)
End If
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,574
Messages
6,131,492
Members
449,653
Latest member
aurelius33

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