PDA

View Full Version : Compare Data and Tabulate Fields Using VBA



deaerator
08-14-2012, 07:50 PM
Hi, I am trying to write a VBA code. I have different scenarios with two primary keys and corresponding data. I would like to compare the data for different scenarios and also based upon the criteria I specify. I would like to only populate data if the data in any one of the scenarios is greater than 90. If the data in any one of the scenarios is not greater than the predefined criteria which for this example is 90, I do not want the data to be listed in the table including the primary keys. See below for an example.

Input Data
Scenario PrimaryKey Primary Key2 TestData1
Test1 Key1 Data1 98
Test1 Key1 Data2 99
Test1 Key1 Data3 94
Test1 Key2 Data1 56
Test1 Key2 Data2 45
Test1 Key3 Data1 85
Test2 Key1 Data1 95
Test2 Key1 Data2 80
Test2 Key1 Data3 85
Test2 Key2 Data1 40
Test2 Key2 Data2 45
Test2 Key3 Data1 90
Test3 Key1 Data1 85
Test3 Key1 Data2 102
Test3 Key1 Data3 80
Test3 Key2 Data1 32
Test3 Key2 Data2 98
Test3 Key3 Data1 85

Output
PrimaryKey Primary Key2 Test1 Test2 Test3
Key1 Data1 98 95 85
Key1 Data2 99 80 102
Key1 Data3 94 85 80

Key2 Data2 45 45 98
Key3 Data1 85 90 85

If you notice in the Output, I do not want Key2 Data1 not listed in the table as the data in none of the scenarios match my criteria. .If for some scenarios, PrimaryKey and Primary Key2 does not exist, I would like to populate it as N/A

Any help would be appreciated.

Thanks