Pull Data from Multiple Excel Files into a Summary Excel File to Create Graphs

ThomasE

New Member
Joined
Nov 15, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have a set of Excel sheets that are outputs from different tests. There are 9 raw data files, and they are sequenced by when the test was conducted.

001_X_PreSine.xlsx
002_X_Random.xlsx
003_X_PostSine.xlsx
004_Y_PreSine.xlsx
005_Y_Random.xlsx
006_Y_PostSine.xlsx
007_Z_PreSine.xlsx
008_Z_Random.xlsx
009_Z_PostSine.xlsx

X, Y, and Z in the file names above will always be grouped together, but the letters could be in any order (X, Y, Z / X, Z, Y / Y, Z, X / etc.).

I want to take the data from the PreSine and PostSine files, which always starts on line 25 and ends on line 2024 of the first sheet and graph the data showing PreSine and PostSine for the same axis (X, Y, Z) in the same graph.

For the graphs, the X-values come from column B, and Y-values come from column G, I, K, and M. Data labels would be "Control", "X-Response", "Y-Response", and "Z-Response" with a prefix of either "Pre Sine" or "Post Sine" as appropriate.

Is it possible to program this by having all of the raw data files and summary file with graphs in the same folder?
 

Attachments

  • Example Output Graph.png
    Example Output Graph.png
    82.5 KB · Views: 14

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi *ThomasE and Welcome to the Board! I'm not following this... " but the letters could be in any order (X, Y, Z / X, Z, Y / Y, Z, X / etc.)". So they may be in any order but they need to be combined the same way? I'm not following the file numbering system (001, 002, 003, etc.)? Or.. You want to combine them in all different ways? What about the Random file results? You can chart arrays. It seems like you could load each sheet's data into a multi-dimensional array and then just chart the array data you want. Does each sheet contain the same number or data items/rows? U can have all files easily in the same folder location but what is the summary file? Is it the file that has the code and does the charting. Maybe a bit more info will get U started. HTH. Dave
 
Upvote 0
@NdNoviceHlp Thank you for your reply. Let me see if I can clarify. A technician is going to run 9 tests for a piece of hardware. The sequence is PreSine, Random, and PostSine for each of the 3 orthogonal axes (X, Y, Z). The customer will define which axis is tested 1st, 2nd, and 3rd, so that each set of 3 tests could be any combination of X, Y, Z, BUT they will always be a set.

PreSine X
Random X
PostSine X
PreSine Y
Random Y
PostSine Y
PreSine Z
Random Z
PostSine Z

or it could be something like

PreSine Y
Random Y
PostSine Y
PreSine X
Random X
PostSine X
PreSine Z
Random Z
PostSine Z

etc.

To keep track of all of the tests, the technician adds a suffix in the sequence they were done: 001-009 and the data from each of the 9 tests is output by the program into an Excel file. That Excel file for the PreSine and PostSine tests has exactly the same number of columns and rows.

What I want to do is automatically create a comparative graph of the PreSine and PostSine data (which I am now realizing did not upload properly in my original post - see new attachment). I am envisioning that I would have a new Excel file that can sort through the other 9 files in the folder, pick out the PreSine and PostSine files and overlay the data in 3 separate graphs for X, Y, and Z.

At the moment, I create a new Excel document in the same location as the raw data files, create a chart, and then individually open each raw data file and select the Frequency column (B25:B2024) and corresponding Amplitude column (G25:2024; I25:I2024; K25:K2024; or M25:M2024) for each data set.
 

Attachments

  • Sine Sweep Overlay.JPG
    Sine Sweep Overlay.JPG
    98.6 KB · Views: 6
Upvote 0
Sorry, not seeing a place to edit my message. The new Excel document would have 3 graphs like the one I had in my last post. Data for PreSine and PostSine in a single graph for each of the orthogonal axes (X, Y, Z).
 
Upvote 0
Seems like snow and blizzard for a few days so I'll mess around with some code for you. If you could post a data file on this site without any other info it would be immensely helpful. I think I have a grasp of your objective but I'd like to further understand it. The chart shows a PreSine control... is this the Random file and if not what's up with the Random file? 3 separate charts for each group of nine (X,X,Z)... OK. Do you have a folder location to use/create ie. ("C:\Testfolder\")? Will there only be 9 files and the summary file there? If not, how to group/ID the 9 related files in the folder? Dave
 
Upvote 0
The Random file is more of confirmation that the specific test was done and is available for review in detail if there is an anomaly.

The test software generates a graph for all of the tests, but the critical thing is checking if the PreSine and PostSine data are different, thus the overlays - this indicates if something went wrong with the unit under test. For whatever reason, the test software does not automatically do this. Maybe providing more detail than you want, but this is for vibration testing - the setup is 1 single axis accelerometer (control) that tells the software/hardware what g-force to impart and 1 triaxial response accelerometer (X, Y, Z) mounted on the unit under test that measures what is happening in all 3 axes during the test. PreSine and PostSine are low level g-accelerations and the Random is a test that imparts the full expected g-accelerations (much more violent). If something breaks on the unit under test during the random test, you can see this in the data overlays.

For file location, I can use a location on my C:\ to process, if that is easiest, but it will ultimately go onto a SharePoint location. The only files in the folder will be the 9 files and the summary file.

Thank you so much for your help! Hopefully you weather the blizzard well!

001_PreSine_Z.xlsx
ABCDEFGHIJKLMN
1Freq Domain Data: Acceleration
2 PtFrequency Reference Control Drive HInv Chan: 1 Chan: 2 Chan: 3 Chan: 4
3 Ampl Phase Ampl Phase Ampl Phase Ampl Phase
4 (Hz) (g) (g) (V-pk) (V/g) (g) (Deg) (g) (Deg) (g) (Deg) (g) (Deg)
5
61200.250.2505130.0456560.182250.25051393.50210.0033683.98310.009411107.19810.25005598.8856
7220.04610.250.250050.0456770.1826720.2500593.60270.00320985.18890.009385106.16790.24962398.9986
8320.09230.250.2490040.0458860.1842780.24900493.66510.00284987.23830.009245106.13740.24852899.0793
9420.13870.250.2496620.0458820.1837780.24966293.52740.00258285.91330.009133106.94480.24902898.9322
10520.18510.250.2505180.0457530.1826340.25051893.60010.00260191.80420.009095107.97740.24969798.9769
11620.23160.250.2517960.0454420.180470.25179693.59570.00282995.39050.009292108.06290.25094398.9596
12720.27830.250.252330.0451280.1788430.2523393.59390.00331795.67760.009643106.44950.25157598.9414
13820.32510.250.2516860.0449880.1787480.25168693.50820.00322192.18060.009611105.46470.2509998.8596
14920.37190.250.2510280.0449250.1789620.25102893.33260.00307889.33420.009557104.82650.25043298.6546
151020.41890.250.2503340.0449390.1795160.25033493.32210.00305189.660.009572105.02190.24976698.6086
161120.4660.250.2504490.0448980.179270.25044993.15210.00294588.42140.00958104.36630.24983298.4063
171220.51320.250.2512550.0446890.1778630.25125593.08640.00301584.97510.009624103.33140.25062198.3161
181320.56050.250.2517830.0444440.1765180.25178393.07530.00328787.11440.009695101.94690.25113298.2926
191420.60790.250.2509620.0443890.1768750.25096293.09420.00330392.90980.0097591020.25024298.3121
201520.65540.250.2501220.0444390.177670.25012293.09560.00285899.37540.009625102.38070.24936598.3089
211620.7030.250.2494490.0445640.1786480.24944992.95970.00248198.73480.009458102.56140.24868698.1717
221720.75080.250.2505460.0444290.1773290.25054692.79410.00235790.3040.009249102.02570.24974797.9959
231820.79860.250.2519540.0440960.1750150.25195492.70950.0025188.00080.00922101.63350.2512497.887
241920.84660.250.2521820.0438180.1737540.25218292.71030.00285985.83660.009292100.93710.25155497.8546
252020.89460.250.2519810.0436190.1731060.25198192.67310.00335788.27780.00931899.47880.25135197.7994
262120.94280.250.2505620.0436560.1742330.25056292.7470.00320696.5110.0093798.56270.24995697.889
272220.99110.250.2499120.0437340.1749980.24991292.75240.002885104.1720.00945398.61250.2492197.8747
282321.03950.250.2499240.0437450.1750330.24992492.70760.002724109.07860.00923797.75120.24925497.8168
292421.0880.250.2506280.0436250.1740640.25062892.62630.002437108.22750.00908497.92310.2500297.7144
302521.13660.250.2513680.043410.1726940.25136892.4680.002495103.47490.0091896.94430.25073797.5493
312621.18540.250.2516960.0431920.1716030.25169692.26090.00271693.37980.00928695.48040.25109197.3189
322721.23420.250.2517670.042980.1707130.25176792.08610.0028988.76640.00920494.7360.25127297.1032
332821.28320.250.2514040.042840.1704040.25140492.04290.0032988.7970.00901994.03180.25083897.037
342921.33230.250.2505310.042850.1710360.25053192.03310.00328491.06780.00901894.32880.24994597.0336
353021.38150.250.2503410.0428370.1711140.25034192.0180.0031396.18630.00922494.69210.24977697.0243
363121.43080.250.2500320.0428590.1714160.25003291.87880.002801101.02470.00929995.37560.24940196.893
373221.48020.250.250690.0427420.1704990.2506991.80660.00283898.95110.00921496.20410.25004896.8123
383321.52970.250.2517780.0424590.1686380.25177891.83120.00336396.40920.00916596.71340.25122196.8103
393421.57930.250.2518650.0422340.1676860.25186591.69960.00329395.74870.00900196.50670.25140596.6751
403521.62910.250.2515880.0420820.1672640.25158891.65830.0034898.36270.00900894.27730.25119896.6322
413621.6790.250.2516270.0418890.1664720.25162791.66010.00389695.630.00901293.05870.25133596.6088
423721.7290.250.2509920.041820.1666180.25099291.61710.00390394.6620.00907292.78770.25068996.5376
433821.77910.250.2498890.0419210.1677580.24988991.4360.00349994.88130.00881692.82770.24957396.3262
443921.82930.250.2497550.041970.1680450.24975591.34770.00318494.30710.00888393.39840.24939796.2204
454021.87960.250.2508670.0417940.1665990.25086791.49340.00330791.78330.00891193.63520.25054596.3605
464121.93010.250.2511020.0416390.1658260.25110291.48280.00332195.62380.00898994.0470.25076296.364
474221.98060.250.2510290.0415250.165420.25102991.38510.00319998.51460.00890692.71860.25061196.2584
484322.03130.250.2508840.041440.1651750.25088491.28520.003236101.84260.00887993.09230.25039696.1349
494422.08210.250.2509520.041340.1647330.25095291.31290.003574102.40460.00896993.69250.25050196.1322
504522.1330.250.2514970.0411360.1635630.25149791.15790.00406298.25930.00888392.32440.2511395.9482
514622.18410.250.2510040.0410590.163580.25100491.00090.00412899.0260.00901291.91990.25058195.7857
524722.23520.250.2505690.0410240.1637250.25056990.94220.00384699.49060.0090692.26580.2501595.7123
534822.28650.250.2501440.041050.1641040.25014490.93070.003861101.14670.00896791.8820.24980395.6869
544922.33790.250.2510480.0408760.162820.25104890.99720.003911101.37210.00889792.52150.25065695.7352
555022.38940.250.2516140.040650.1615560.25161491.02720.004321101.30520.00890693.38610.25124795.7401
565122.4410.250.2516740.0404620.1607720.25167490.65680.00422395.06010.00863793.28230.25146595.3574
575222.49280.250.2509630.0404020.1609890.25096390.55610.00404791.56120.00857592.04560.25075395.2463
585322.54460.250.2506680.0403580.1610040.25066890.50920.00414691.24120.00871291.35380.2503695.1776
595422.59660.250.2505830.0402970.1608110.25058390.5010.00407190.78630.00873192.81470.25021495.1616
605522.64870.250.2508030.0402010.1602910.25080390.41880.00380291.92910.00863592.69650.25044495.0676
615622.70090.250.2506610.0401260.1600790.25066190.54570.00354297.94230.00861592.86220.25028495.1841
625722.75330.250.2501910.0401450.1604580.25019190.57210.003606104.44510.00857492.23890.24989295.2161
635822.80570.250.2508010.040020.1595690.25080190.43860.00398102.15220.00845692.93880.25057595.0675
645922.85830.250.2516030.0397940.1581630.25160390.21030.00423496.80090.00844393.29270.25138894.8228
656022.9110.250.2518540.0395650.1570960.25185490.14830.00430690.24680.00855792.10140.25166694.7339
666122.96390.250.2507520.0395550.1577480.25075290.16120.00441290.38640.0084691.35970.2506694.7192
676223.01680.250.2500160.0396060.1584120.25001690.1140.00456395.97210.00836391.46870.24983594.6596
686323.06990.250.2501260.0395920.158290.25012690.08690.00452899.21410.00839592.10270.24983394.6418
696423.12310.250.2506280.0394860.1575460.25062890.07290.00444494.72480.00840192.67240.25036194.6153
706523.17640.250.2511750.0393240.1565590.25117589.91450.00454591.30440.00828392.41570.25101394.4296
716623.22980.250.2517240.0390940.1553040.25172489.81590.00455691.73520.00830691.53530.25160894.3125
726723.28340.250.2511110.0390030.155320.25111189.83840.00461595.31320.00829792.70140.25097994.3332
736823.33710.250.2503420.0390230.155880.25034289.84370.00476795.61630.00837992.52860.2501994.3302
746923.39090.250.2503650.0389960.1557560.25036589.70790.00500695.50980.00841592.13880.25024494.1846
757023.44480.250.2506450.0389050.1552210.25064589.55490.00521295.38220.00833991.80230.25069394.0167
767123.49890.250.2510850.0387630.1543810.25108589.40830.00493794.10250.00813991.59660.25114193.8825
777223.55310.250.2508490.0386840.1542130.25084989.32390.00490894.5840.00831790.01480.25084993.768
787323.60740.250.2510780.0385650.1535980.25107889.20340.00502294.71020.00833390.29520.25102493.6064
797423.66180.250.2517130.0383360.1523020.25171389.04520.00487291.29010.00822990.21260.25159593.4305
807523.71640.250.2510240.0382570.1524030.25102488.98850.00459487.48940.0081291.18850.25086193.3638
817623.77110.250.2504070.0382660.1528160.25040788.9910.00448187.73040.00797391.85990.25026793.3714
827723.82590.250.2505320.0381890.1524330.25053288.92890.00472188.45350.00783891.02660.25044793.2896
837823.88080.250.2508710.0380710.1517540.25087188.76050.0049784.42370.00799390.48630.25074193.0873
847923.93590.250.2504520.0380510.1519310.25045288.44780.0044379.36490.00796989.72310.25023692.7626
858023.99110.250.2513980.037850.1505570.25139888.58550.00455283.38150.00794288.97560.25120292.8987
868124.04640.250.2515640.037660.1497020.25156488.66190.00475486.86350.00796889.0050.25150392.9727
878224.10180.250.2508270.037620.1499840.25082788.67340.00482688.71770.00801890.19410.250892.9802
888324.15740.250.2504570.0375960.1501080.25045788.60980.00500788.30910.00800790.07330.250592.9029
898424.21310.250.2504690.0375560.1499440.25046988.54530.00480889.82380.0078590.1740.25057292.8495
908524.2690.250.2507960.0374430.1492960.25079688.38150.00459989.73170.00771989.27670.25097192.6657
918624.32490.250.2509680.0373410.1487880.25096888.50680.00493389.95880.00787988.70540.25106292.7652
928724.3810.250.2507710.0372650.1486010.25077188.46840.00500389.73270.00800890.26850.25081392.6973
938824.43720.250.2504140.0372450.1487340.25041488.26440.00496589.6420.00813991.42310.25041592.4654
948924.49360.250.2509410.0371090.1478820.25094188.23970.00472793.07520.0081890.99270.250992.4598
959024.550.250.2508210.0370240.147610.25082188.14940.00458791.82450.00797890.9920.25086392.3742
969124.60670.250.2507280.0369670.1474380.25072888.05410.00471489.42470.00780889.39940.25079292.2504
979224.66340.250.2505130.0369210.147380.25051387.96010.00473488.78810.00763790.95960.2505692.1356
989324.72030.250.2505790.0368560.1470840.25057987.97050.00482789.89910.0078892.14480.25076992.16
999424.77730.250.2506250.0367930.1468040.25062587.90260.00463589.62630.00801291.49890.25083392.0905
1009524.83440.250.2506810.0367260.1465050.25068187.82610.00468891.56740.00793490.85730.25075992.0058
1019624.89170.250.2512290.0365560.1455090.25122987.86540.00514293.12570.00797890.61570.25138192.0095
1029724.9490.250.2512170.0364330.1450250.25121787.84490.00519593.23690.00792389.98760.2514691.9667
1039825.00660.250.2514150.0362880.1443340.25141587.68420.00521292.66830.00778689.74450.25162591.8092
1049925.06420.250.2517470.0360720.1432870.25174787.52390.00532286.10740.00764790.12350.25199391.6453
10510025.1220.250.2507550.0360570.1437950.25075587.48560.00512389.8330.00771990.33690.2509291.6101
APEX SL Data
 
Upvote 0
Quick question. Are the "X" (column "B") values always the same for all files or does each file (X_pre-sine, X_post-sine, Y_presine, Y_Postsine, etc) each have a unique set of "X" values? I'll assume that each file has it's own set of "X" values but it would be easier if they all happen to be the same. Weather update, it's not below zero yet so it's just raining crazy until about 2hrs from now when the weather prognosticators say it's going to start snowing and blowing for at least the next 2 days. Dave
 
Upvote 0
It appears that the X values will always be the same after checking a few files - I did not think of that. I can see that making it easier.

Sounds like a grand time with the weather. Hello winter!
 
Upvote 0
Weather update... it turned to snow and the power went out. Hooray! Finally a chance to be a family hero. I purchased a generator and had my house wired about 3 years ago and finally now have a chance to use it for an extended interval. I wired the important stuff: some plugs and lights, fridges, tv, pc's and internet. So still quite comfy. I just about have some code ready for you to trial which I'll post after a bit more testing. Just wondering, it's fairly easy to have just 1 chart and place either the X, Y or Z axis test on it rather than having 3 charts. What would you prefer? Ah CRAP... the power just came back on. So much for the herodom. Dave
 
Upvote 0
I've got some code ready to trial but it only uses 1 chart... can be adapted to 3 charts if preferred. To start, create a new wb in your Testfolder location that has the data files. Insert a blank scatter chart with smooth lines ("Chart 1"), copy and paste the following code (either to sheet or module code) and then save your file with whatever name as a .xlsm file.
VBA Code:
Option Explicit
Dim Xarr() As Variant, Yarr() As Variant, Zarr() As Variant

Public Sub LoadChartData(AxisName As String)
'AxisName "X","Y", or "Z"
Dim SourceFolder As String, SourceFiles As Object, sourceFile As Object
Dim WbSource As Workbook, DataWs As Worksheet, S As Series
Dim LastRow As Integer, TotRows As Integer, ArCnt As Integer
Dim RowCnt As Integer, SerCnt As Integer
On Error GoTo ErFix
Application.ScreenUpdating = False
Application.DisplayAlerts = False

SourceFolder = ThisWorkbook.Path & "\"
' Create a FileSystemObject to work with files in the folder
Set SourceFiles = CreateObject("Scripting.FileSystemObject").GetFolder(SourceFolder).Files

' Loop through each file in the folder
For Each sourceFile In SourceFiles
'only open .xlsx files
If sourceFile.Name Like "*.xlsx" Then
'don't include "Random" files
If InStr(sourceFile.Name, "Random") = 0 Then
' Open the source workbook
Set WbSource = Workbooks.Open(sourceFile.Path)
Set DataWs = WbSource.Worksheets("Customers")
With DataWs
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
TotRows = LastRow - 25

'Load files to Array
'XArr(1 to 2, 1 to 5, 1 to TotRows)
'presine(1) postsine(2); Col"B"(1), Col"G"(2), Col"I"(3), Col"K"(4), Col"M"(5); Row data 25 to Lastrow
'load X files to array
If InStr(sourceFile.Name, "X") Then
    ReDim Preserve Xarr(2, 5, TotRows + 1)
    If InStr(sourceFile.Name, "PreSine") Then
    For RowCnt = 25 To LastRow
    ArCnt = 1
    Xarr(1, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, 2)
    For SerCnt = 7 To 13 Step 2
    ArCnt = ArCnt + 1
    Xarr(1, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, SerCnt)
    Next SerCnt
    Next RowCnt
    Else 'postsine
    For RowCnt = 25 To LastRow
    ArCnt = 1
    Xarr(2, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, 2)
    For SerCnt = 7 To 13 Step 2
    ArCnt = ArCnt + 1
    Xarr(2, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, SerCnt)
    Next SerCnt
    Next RowCnt
    End If
'load Y files to array
ElseIf InStr(sourceFile.Name, "Y") Then
    ReDim Preserve Yarr(2, 5, TotRows + 1)
    If InStr(sourceFile.Name, "PreSine") Then
    For RowCnt = 25 To LastRow
    ArCnt = 1
    Yarr(1, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, 2)
    For SerCnt = 7 To 13 Step 2
    ArCnt = ArCnt + 1
    Yarr(1, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, SerCnt)
    Next SerCnt
    Next RowCnt
    Else 'postsine
    For RowCnt = 25 To LastRow
    ArCnt = 1
    Yarr(2, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, 2)
    For SerCnt = 7 To 13 Step 2
    ArCnt = ArCnt + 1
    Yarr(2, ArCnt, RowCnt - 24) = DataWs.Cells(RowCnt, SerCnt)
    Next SerCnt
    Next RowCnt
    End If
'load Z files to array
    ElseIf InStr(sourceFile.Name, "Z") Then
    ReDim Preserve Zarr(2, 5, TotRows + 1)
    If InStr(sourceFile.Name, "PreSine") Then
    For RowCnt = 25 To LastRow
    ArCnt = 1
    Zarr(1, ArCnt, RowCnt - 25) = DataWs.Cells(RowCnt, 2)
    For SerCnt = 7 To 13 Step 2
    ArCnt = ArCnt + 1
    Zarr(1, ArCnt, RowCnt - 25) = DataWs.Cells(RowCnt, SerCnt)
    Next SerCnt
    Next RowCnt
    Else 'postsine
    For RowCnt = 25 To LastRow
    ArCnt = 1
    Zarr(2, ArCnt, RowCnt - 25) = DataWs.Cells(RowCnt, 2)
    For SerCnt = 7 To 13 Step 2
    ArCnt = ArCnt + 1
    Zarr(2, ArCnt, RowCnt - 25) = DataWs.Cells(RowCnt, SerCnt)
    Next SerCnt
    Next RowCnt
    End If
End If
WbSource.Close savechanges:=False
End If
End If
Next sourceFile

'remove previous series
For Each S In Sheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection
      S.Delete
Next S
'Call ChartIt Sub for Axis Name
If AxisName = "X" Then
Call ChartIt("X Axis Test", Xarr, TotRows, "Pre Sine")
Call ChartIt("X Axis Test", Xarr, TotRows, "Post Sine")
ElseIf AxisName = "Y" Then
Call ChartIt("Y Axis Test", Yarr, TotRows, "Pre Sine")
Call ChartIt("Y Axis Test", Yarr, TotRows, "Post Sine")
Else
Call ChartIt("Z Axis Test", Zarr, TotRows, "Pre Sine")
Call ChartIt("Z Axis Test", Zarr, TotRows, "Post Sine")
End If

ErFix:
If Err.Number <> 0 Then
MsgBox "LoadChartDataError"
End If
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Set SourceFiles = Nothing
End Sub

Public Sub ChartIt(ChrtTitle As String, InArr As Variant, Trows As Integer, ChtType As String)
'ChrtTitle: "X Axis Test", "Y Axis Test", or "Z Axis Test"
'InArr: Xarr, Yarr, or Zarr
'TRows: total number of data rows
'ChtType: "Pre Sine" or "Post Sine"
Dim TempXArr() As Variant, TempYArr() As Variant, SeriesList As Variant, ColourList As Variant
Dim Cnt As Integer, Cnt2 As Integer, ChtInt As Integer, First As Integer, Last As Integer
'xseries name array
SeriesList = Array("Control", "X-Response", "Y-Response", "Z-Response")
If ChtType = "Pre Sine" Then
'series colour list
ColourList = Array(3, 4, 5, 6)
ChtInt = 1
First = 1
Last = 4
Else
ColourList = Array(7, 8, 9, 10)
ChtInt = 2
First = 5
Last = 8
End If

'Xvalues from array to temp array
ReDim TempXArr(Trows + 1)
For Cnt = 1 To Trows + 1
TempXArr(Cnt) = InArr(ChtInt, 1, Cnt)
Next Cnt

With Sheets("Sheet1").ChartObjects("Chart 1").Chart
'add chart series
For Cnt = First To Last
'y values from array to temp array
ReDim TempYArr(Trows + 1)
For Cnt2 = 1 To Trows + 1
If ChtType = "Pre Sine" Then
TempYArr(Cnt2) = InArr(ChtInt, Cnt + 1, Cnt2)
Else
TempYArr(Cnt2) = InArr(ChtInt, Cnt - 3, Cnt2)
End If
Next Cnt2

'add series to chart
.SeriesCollection.NewSeries
.SeriesCollection(Cnt).XValues = TempXArr
.SeriesCollection(Cnt).Values = TempYArr
'name and colour series
If ChtType = "Pre Sine" Then
.SeriesCollection(Cnt).Name = ChtType & " " & SeriesList(Cnt - 1)
.SeriesCollection(Cnt).Border.ColorIndex = ColourList(Cnt - 1)
Else
.SeriesCollection(Cnt).Name = ChtType & " " & SeriesList(Cnt - 5)
.SeriesCollection(Cnt).Border.ColorIndex = ColourList(Cnt - 5)
End If
'format series
.SeriesCollection(Cnt).Border.Weight = xlMedium
.SeriesCollection(Cnt).Border.LineStyle = xlContinuous
.SeriesCollection(Cnt).MarkerStyle = xlMarkerStyleNone
Next Cnt
'add series legend
.HasLegend = True
.Legend.Position = xlLegendPositionBottom
.Legend.AutoScaleFont = True
'add chart title
.HasTitle = True
.ChartTitle.AutoScaleFont = False
.ChartTitle.Characters.Text = ChrtTitle
.ChartTitle.Characters.Font.Size = 12
End With

'y axis format
With Sheets("Sheet1").ChartObjects("Chart 1").Chart.Axes(xlValue)
.MinimumScale = 0.001
.MaximumScale = 10
.ScaleType = xlLogarithmic
.HasMajorGridlines = True
.MajorGridlines.Border.ColorIndex = 17
.TickLabels.AutoScaleFont = False
.TickLabels.Font.Bold = True
.TickLabels.Font.Size = 10
.HasTitle = True
.AxisTitle.Characters.Text = "Amplitude"
.AxisTitle.AutoScaleFont = False
.AxisTitle.Left = 1
.AxisTitle.Font.Size = 10
End With

'x axis format
With Sheets("Sheet1").ChartObjects("Chart 1").Chart.Axes(xlCategory)
.MinimumScale = 20 '18
.MaximumScale = 2000 '26
.ScaleType = xlLogarithmic
.HasMajorGridlines = True
.MajorGridlines.Border.ColorIndex = 17
.TickLabels.AutoScaleFont = False
.TickLabels.Font.Bold = True
.TickLabels.Font.Size = 10
.TickLabelPosition = xlTickLabelPositionLow
.HasTitle = True
.AxisTitle.Characters.Text = "Frequency"
.AxisTitle.AutoScaleFont = False
.AxisTitle.Font.Size = 10
End With
End Sub
To operate, call the desired sub....
VBA Code:
Call LoadChartData("X")
'Call LoadChartData("Y")
'Call LoadChartData("Z")
Seems like it works but it's hard to tell with only a small portion of data from 1 file. It's still mid blizzard here so I'll likely be able to make any revisions as required. Dave
 
Upvote 1
Solution

Forum statistics

Threads
1,224,808
Messages
6,181,072
Members
453,020
Latest member
mattg2448

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