VBA to arrange Dynamic data series

smide

Board Regular
Joined
Dec 20, 2015
Messages
162
Office Version
  1. 2016
Platform
  1. Windows
Hello.

I'm receiving data from external source (on every 5-10) minutes for analysis and I'm interested only for last five samples.
Data range is a quite extensive on two Sheets (Sheet1 , row 3 columns A-EN and same for Sheet2).
I would like to avoid all those annoying and time consuming copy-paste with some simple macro.

Here is my current situation:

- my last five samples/prices are always in rows 4-8 (every second column - B,D,F,H...EN)
- left columns (A,C,E..) are date and time columns - time when price was recived

What I would like to do is:

In the case that data series contains all five prices and new obtained price differs from current last series price then:

1) when new price(s) is obtained I would like to eliminate (delete) first price (oldest) from those series, then move all other prices one place downwards and finally put that new obtaind price
to the last position in series (row 8).


In the case that data series contains less than five prices and new obtained price differs from current last series price then:

2) just add that new obtaind price in first empty cell (rows 4-8)

If new obtained price is equal to last data series price then - do nothing!

Example.

- product names: row3
- data series/prices for product: always in the same column as product (in rows 4-8)
- date an time: always in "left" column
- new obtained price: row 3 to the right of product cell

Sheet1
- Product 1 - all five samples are in data series - if new obtaind price differs from last price (69) then do 1)
- Product 2 - three samples in series (less than five) - if new obtaind price differs from last price just add new obtained in first empty cell
- Product 3 - new obtained price is equal to last series price (19) - do nothing!
cells C3,E3,G3 - new obtained prices for Product's

ABCDEFG
1
2
3Product 175Product 248Product 319
412.09. 23:132511.09. 22:104912.09. 11:0222
512.09. 23:193616.09. 10:553513.09. 15:1219
614.09. 12:281817.09. 10:3037
716.09. 15:2616
816.09. 15:2869

<tbody>
</tbody>


Sheet 1 (after macro run)

ABCDEFG
1
2
3Product 175Product 248Product 319
412.09. 23:193611.09. 22:1049 12.09. 11:0222
514.09. 12:281816.09. 10:553513.09. 15:1219
616.09. 15:261617.09. 10:3037
7 16.09. 15:286948
875

<tbody>
</tbody>

* note : below row 8 (rows 12-75, columns A-EN) I have cells with formulas and I would like to keep them after macro runs
 
Last edited:

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,215,972
Messages
6,128,017
Members
449,414
Latest member
sameri

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