Copy conditionally and paste conditionally

luvbite38

Active Member
Joined
Jun 25, 2008
Messages
368
Hi Guys,

I want to copy a range conditionally and paste conditionally and hoping that some1 would kindly help me outta er,

Condition to copy

Match the value from CopyTo sheet in ColA with the CopyFrom in ColA.

Condition to paste

Paste if the value is true

See Example below

[TABLE="width: 508"]
<tbody>[TR]
[TD]CopyFrom

[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Items
[/TD]
[TD]RandVals1
[/TD]
[TD]RandVals2
[/TD]
[TD]RandVals3
[/TD]
[TD] RandVals4
[/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: right"]30
[/TD]
[TD="align: right"]32
[/TD]
[TD="align: right"]13
[/TD]
[TD="align: right"]6
[/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: right"]33
[/TD]
[TD="align: right"]34
[/TD]
[TD="align: right"]27
[/TD]
[TD="align: right"]40
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: right"]38
[/TD]
[TD="align: right"]29
[/TD]
[TD="align: right"]47
[/TD]
[TD="align: right"]39
[/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: right"]24
[/TD]
[TD="align: right"]9
[/TD]
[TD="align: right"]19
[/TD]
[TD="align: right"]17
[/TD]
[/TR]
[TR]
[TD]ETC
[/TD]
[TD="align: right"]36
[/TD]
[TD="align: right"]13
[/TD]
[TD="align: right"]34
[/TD]
[TD="align: right"]44
[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 855"]
<tbody>[TR]
[TD]CopyTo
[/TD]
[TD]Condition1
[/TD]
[TD]Condition2
[/TD]
[TD]Condition3
[/TD]
[TD]Paste if True in Condition1
[/TD]
[TD]Paste if True in Condition2
[/TD]
[TD]Paste if True in Condition3
[/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]30
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]32
[/TD]
[TD="align: right"]30
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]13
[/TD]
[TD="align: right"]32
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]6
[/TD]
[TD="align: right"]13
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD="align: right"]6
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apple
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]30
[/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]33
[/TD]
[TD][/TD]
[TD="align: right"]32
[/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]34
[/TD]
[TD="align: right"]33
[/TD]
[TD="align: right"]13
[/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]27
[/TD]
[TD="align: right"]34
[/TD]
[TD="align: right"]6
[/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: right"]40
[/TD]
[TD="align: right"]27
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD="align: right"]40
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Mango
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]33
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]34
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]27
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]40
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="colspan: 3"]and So on
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[/TR]
[TR]
[TD]Grapes
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD="align: center"]FALSE
[/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Banana
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]FALSE
[/TD]
[TD="align: center"]TRUE
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Hope it makes sense.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I can't believe, i fixed it without any help....

if anyone ever need doing something similar use the following code.

Make sure to change the references to meet you need.

Code:
Sub FirstArrival()
    Dim rng As Range, r As Range
    With Sheets("ArrivalProfileData")
        Set rng = .Range("A1", .Range("A" & Rows.Count).End(xlUp)).Resize(, 22)
    End With
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For Each r In rng.Columns(1).Cells
            Set .Item(r.Value) = r(, 2).Resize(, 21)
        Next
        For Each r In Sheets("Calculation+PTCache").Range("a1").CurrentRegion.Columns(1).Cells
            If (r(, 11) = True) * (.exists(r.Value)) Then
                .Item(r.Value).Copy
r(1, 17).PasteSpecial xlPasteValues, Transpose:=True
            End If
Next
End With
Set rng = Nothing
Application.CutCopyMode = False
End Sub

I am sooooooo happpy "Borat"
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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