循环浏览工作表并将值添加到下拉列表 - VBA

时间:2017-12-13 19:06:12

标签: excel vba for-loop dropdown

目标

我想循环浏览五张纸并根据一些要求填写第六张表格中的下拉列表。

问题

我不知道如何填充下拉列表,让它们动态化并循环显示五张。

描述

在第六张(下拉列表)中,列E包含我想要与五张纸中的第一行(E1:GG1)进行比较的名称。每列都有一堆1。

如果E列(下拉列表)中的名称与行中的名称(五张中的一张)之间存在匹配,那么' 1'在该行的列中,下拉列表应填充A列中的ID。

所需的输出

enter image description here

enter image description here

代码

#include<iostream>
#include<string>
using namespace std;

int main()
{
    float n = 5, support1 = 0, support2 = 0, support3 = 0;
    string item1, item2;
    //dataset fixed
    string tra1[5] = { "milk", "beer" , "coffee" , "sugar" , "detergen" };
    string tra2[5] = { "egg", "flour" , "milk" , "sugar" };
    string tra3[5] = { "coffee", "butter" , "cigarette" , "sugar" };
    string tra4[5] = { "doritos", "tea" , "coconut oil" , "soap" };
    string tra5[5] = { "detergen", "milk" , "sugar" , "coca cola" };

    cout << "item 1 : "; cin >> item1;//for example coffee
    cout << "item 2 : "; cin >> item2;//for example sugar
    cout << endl << "------------------------------" << endl;

    //i think this is where the problem is
    for (int i = 0;i < n;i++)
    {
        //tra1
        if (item1 == tra1[5]) { support1 + 1; }
        if (item2 == tra1[5]) { support2 + 1; }
        if (item1 == tra1[5] && item2 == tra1[5]) { support3 + 1; }

        //tra2
        if (item1 == tra2[5]) { support1 + 1; }
        if (item2 == tra2[5]) { support2 + 1; }
        if (item1 == tra2[5] && item2 == tra2[5]) { support3 + 1; }

        //tra3
        if (item1 == tra3[5]) { support1 + 1; }
        if (item2 == tra3[5]) { support2 + 1; }
        if (item1 == tra3[5] && item2 == tra3[5]) { support3 + 1; }
        //tra4
        if (item1 == tra4[5]) { support1 + 1; }
        if (item2 == tra4[5]) { support2 + 1; }
        if (item1 == tra4[5] && item2 == tra4[5]) { support3 + 1; }
        //tra5
        if (item1 == tra5[5]) { support1 + 1; }
        if (item2 == tra5[5]) { support2 + 1; }
        else if (item1 == tra1[5] && item2 == tra5[5]) { support3 + 1; }
    }

    //print how many times are coffee and sugar purchased
    cout << "Transaction done " << item1 << " : " << support1 << endl;
    cout << "Transaction done " << item2 << " : " << support2 << endl;
    cout << "Transaction done " << item2 << " dan " << item2 << " : " << support3 << endl;
    cout << endl << "------------------------------" << endl;

    float result1,result2,result3;
    result1 = (support1 / n) * 100;
    result2 = (support2 / n) * 100;
    result3 = (support3 / n) * 100;

    cout << "Item 1 : " << item1 << "\t" << "Item 2 : " << item2 << endl;
    cout << "support " << item1 << " : " << result1 << endl;
    cout << "support " << item2 << " : " << result2 << endl;
    cout << "support " << item1 << " dan " << item2 << " : " << result3 << endl;

    return 0;
}

0 个答案:

没有答案