Search : in
By :

Excel macro copying cells based on criteria

Last answer on Nov 7, 2009 4:23:07 am GMT nsy2204, on Nov 7, 2009 1:43:14 am GMT 
 Report this message to moderators

Hello,
If problem excel

If cell H of worksheet A = cell E of worksheet B
and/or
If cell J of worksheet A = Cell H of worksheet B
and/or
If cell K of worksheet A = cell I of worksheet B

then copy cell O of worksheet A to cell L of worksheet B

(put in other words
if H2, J2, K2 of worksheet A = E1, H1, I1 of worksheet B
then copy O2 of worksheet A to L1 of worksheetB)

if H3, J3, K3 of worksheet A = E5, H5, I5 of worksheet B
then copy O3 of worksheet A to L5 of worksheetB)

i need the macro to match and copy for the whole worksheet of A and B
Data from worksheet A is only to be used once

Configuration: Windows Vista Internet Explorer 7.0

Best answers for « excel macro copying cells based on criteria » in :
Copy rows based on a condition ShowCopy rows based on a condition Issue Solution Note Issue How can I have excel copy the entire row of data from worksheet Employee Inventory to another worksheet called EEs if column Q contains TERM. I've tried almost everything but...
Excel – Macro to detect and hide blank rows ShowExcel – Macro to detect and hide blank rows Issue Solution Note Issue I want a macro to unhide about 20 blank rows copy values into the top row then hide the remaining rows (some cells have fill though) then the next time it will...
Keyboard /Mouse Tips for Excel ShowKeyboard /Mouse Tips for Excel Intro Other Shortcuts Intro Excel tutorials give hints that make the difference between a needy use and flexibility. Here are some examples: Copy the highlight to the clipboard: [Ctrl + Ins] Paste...
Worksheet - Cells ShowThe Concept of a Cell A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also...

1

 nsy2204, on Nov 7, 2009 4:23:07 am GMT

I tried to do something like this but nothing seems to get copied...

Sub CopyData()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim j As Long, i As Long, lastrow As Long

Set sh1 = Worksheets("Worksheet A")
Set sh2 = Worksheets("Worksheet B")

lastrow = sh1.Cells(Rows.Count, "A").End(xlUp).Row


For i = 2 To lastrow
j = (i - 2) * 4 + 1
If sh1.Cells(i, "H").Value = sh2.Cells(j, "E").Value And _
sh1.Cells(i, "J").Value = sh2.Cells(j, "H").Value And _
sh1.Cells(i, "K").Value = sh2.Cells(j, "I").Value Then
sh1.Cells(i, "O").Copy sh2.Cells(j, "L")
End If
j = j + 4
Next

End Sub

Reply to nsy2204