I'm trying to copy values from one sheet to another, comparing the Key values (columns A & C) and either pasting a value (column E) into the target sheet or adding a row and pasting all three values into A, C, F.
Here's a sample of the data:
SOURCE TABLE
A B C D E
Name Ext Dept Days w22Hrs
------- ------- ------- ------- -------
Alan x101 Level1 MTWTF 8
Brian x102 Level1 MTWTF 30
Claire x103 Level1 MTWTF 40
Denise x104 Level2 MTWTF 16
Denise x105 Level1 MTWTF 24
TARGET TABLE
A B C D E F
Name Ext Dept Days w21Hrs w22Hrs
------- ------- ------- ------- ------- -------
Brian x102 Level1 MTWTF 32
Denise x104 Level2 MTWTF 16
Denise x105 Level1 MTWTF 8
Eric x106 Level1 MTWTF 36
DESIRED RESULT
A B C D E F
Name Ext Dept Days w21Hrs w22Hrs
------- ------- ------- ------- ------- -------
Alan Level1 0 8
Brian x102 Level1 MTWTF 32 30
Claire Level1 0 40
Denise x104 Level2 MTWTF 16 16
Denise x105 Level1 MTWTF 8 24
Eric x106 Level1 MTWTF 36 0
I tried to copy the source data into an array using this code:
set rng = union(range("A2:A6"), range("C2:C6"), range("E2:E6"))
arrTemp = rng.value2
arr = application.transpose(arrTemp)
But all I get is are values from A2:A6. However this works:
set rng = range("A2:E6")
arrTemp = rng.value2
arr = application.transpose(arrTemp)
1 - Is there no easy way to put only the columns I want into the array? (Iterating through cell areas seems inelegant to me.)
2 - Is there an easier way to accomplish the overall goal of updating the target sheet? (Keep in mind I want to update w##Hrs for existing rows AND add new rows when needed.) Or are arrays my best bet? (Would a Collection be better?)
If it makes things easier, I can paste A:D into the target, but source.E still needs to go into target.F.
Thanks!