Excel VBA Copy data from Pivit Table meet certain criteria

hllnll

New Member
Joined
Sep 29, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I'm new to VBA and google is my teacher. I have a difficult time finding or combing the appropriate VBA codes to do this task. I would appreciate it if someone could give me a hand!
I have a Pivit table called "PivitSpeed" with two columns: "Time" (txt format) and "Average of Speed" (number), and filters of location and month and day.
1632897495210.png

What I would like to do is to copy the data that meet the criteria (mentioned below) to a table in the same sheet (same location each time). The final goal is to plot both original pivot data and selected data into one graph, like this one I drew manually.
1632897439959.png

My criteria are period of time (in table "MPE_Period"), there are start time and end time, which varies on different dates. I used INDEX to get those to a table and it changes when the filter of location changes (but too bad it doesn't synchronize with date).
1632897676431.png
the original criteria table("MPE_C") looks like this:
1632898066846.png

Since I have 52 locations and a month of data. I hope to at least get the filtered data that meet the time period (time in between the start and end time) when my pivot filter changes. For example, when I select location 3, and Aug. 5 or 5-9, the data should be automatically screened and copied to a table. Even better, they are plotted in one graph!

I'm not sure if I'm clear about my question. Please let me know if more info is needed. Thank you all!!!!!
 

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.

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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