Is there a way to find a range within a range in Excel?

南楼画角 提交于 2019-12-05 21:19:44

I think what I would do in this scenario is first construct a look-up list consisting of each header and its location. For the key in the list, I would concatenate the header cells together to make a single look-up value. So following on immediately after your code:

Dictionary<string, int> lookUpList = new Dictionary<string, int>();

// Loop through the rows

for (int i = 0; i < valueArray.GetLength(0); i++)
{
    // Identify the header rows

    if (valueArray[i, 0].ToString() == "WR")
    {
        // Concatenate the header strings into a single string

        string header = "";

        for (int j = 0; j < valueArray.GetLength(1); j++)
        {
            header += valueArray[i, j].ToString();
        }

        // Store the header location

        lookUpList.Add(header, i + 1);
    }
}

Bear in mind that this is extempore and I haven't tested it. I'm not sure exactly how the Range.get_Value method places data into the array, so the dimensions might be the wrong way around. Also I'm making assumptions about how to identify header rows in your spreadsheet based on the image of the data you supplied.

Anyway, once constructed you can perform a simple look up to extract the row number of the header:

string userSelectedHeader = "concatenation of whatever the user selected";
int rowNumber = lookUpList[userSelectedHeader];

Does that go some way to helping answer your question?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!