How to make an array that only copies data if there are headers with the same name in both sheets and if column 3 = 0

Bassie

Board Regular
Joined
Jan 13, 2022
Messages
66
Office Version
  1. 2019
Platform
  1. Windows
Hey,

I basically have 2 sheets lets call them Data sheet and Destination sheet.
Data sheet has around 30 columns and Destination sheet has around 15 columns.
I want to populate the 15 columns if they match any of the headers from the data sheet file and if column 3 in the datasheet file is 0

I can do this using a loop but its a file with around 1 million cells so I think using an array would be way better but I am really new to writing Array so would love some help on this.

The outcome would look something like this: (with more columns and on another sheet but I hope you get the idea). As you can see only the rows are copied if column 3 = 0 and if the headers match
DaySales PersonQuantitySalesSalesQuantity
Sales person
7/1/2022Jill0$3,848$ 3,8480Jill
7/1/2022Jack2$ 850$ 2520Jack
7/1/2022John2$ 982$ 2460Jack
7/2/2022Jack0$ 252$ 1,3440John
7/2/2022Jill5$2,315
7/2/2022Jack0$ 246
7/2/2022John3$ 996
7/3/2022John0$1,344
7/3/2022Jack3$ 702
7/4/2022Jack7$3,269
7/4/2022Mary4$1,232
7/5/2022Jill9$2,925
7/4/2022Mary4$1,232
7/5/2022Jill9$2,925


Regards,
Bassie
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Why not just use the new FILTER function?
See: FILTER function - Microsoft Support

By the way, I don't think I would try using Excel on anything that has around 1 million rows!
This would be really easy to do in Microsoft Access with a simple query.

You could also probably use Power Query in Excel to do it as well.
 
Upvote 0
Not sure if you saw, but I had added more comments to my original reply.

Why does it need to be VBA, especially if there is an easy way to do it without VBA?
Note that you can apply the Filter formula in VBA too. If you turn on your Macro Recorder and record yourself entering the formula manually, you will have recorded the VBA code you need to do that.

Whatever you do, I would STRONGLY advise against doing loops in VBA on data that size. Loops are notoriously slow and inefficient, and trying to do them on a range of nearly one million rows is probably not going to perform well.
 
Upvote 0
Not sure if you saw, but I had added more comments to my original reply.

Why does it need to be VBA, especially if there is an easy way to do it without VBA?
Note that you can apply the Filter formula in VBA too. If you turn on your Macro Recorder and record yourself entering the formula manually, you will have recorded the VBA code you need to do that.

Whatever you do, I would STRONGLY advise against doing loops in VBA on data that size. Loops are notoriously slow and inefficient, and trying to do them on a range of nearly one million rows is probably not going to perform well.
Hi!

I want it to be in VBA as its part of a bigger code. I understand that it is not smart to use it on bigger size data but my normal code runes in about 4 mins and has to be ran ones a week so I am fine with it for now.

I would love it to be with an array as I am trying to learn arrays but just cant get this to work.

- Bassie
 
Upvote 0
I want it to be in VBA as its part of a bigger code. I understand that it is not smart to use it on bigger size data but my normal code runes in about 4 mins and has to be ran ones a week so I am fine with it for now.

I would love it to be with an array as I am trying to learn arrays but just cant get this to work.
Sorry, really cannot help you with arrays. Those are not my forte.

I did explain in my reply how you can use VBA though.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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