Compare when variable gets larger than value in list / IEnumerable

Background / context

I am currently creating a function that will take a value and compare it to a list to find at what point the values ​​of the strings get larger. The value I am taking is date and the row contains a series of dates that are the chart titles, and essentially I am trying to find a column in excel where this date will match. Header dates are all weekly dates. I tried to figure out my logic but nothing seems to work, so I thought I would ask here.

The logic behind the code

  • The program creates an IEnumerable to find the cell of records for which we are looking up
  • The program creates an IEnumerable with all dates in the headers.
  • The program takes this date and compares it to IEnumerable at 2. to return the column to which the new date will be sent.

Code to point 2

List<string> Sheet1Rows = new List<string>();
List<string> Sheet2Rows = new List<string>();
List<DateTime> ColumnDates = new List<DateTime>();
//List<int> NewRowsNumber = new List<int>();

for (int row = 9; row <= LastRowSheet1; row++)
{
    Sheet1Rows.Add(ExcelWksht1.Cells[row, 1].Value);
}

for (int row = 9; row <= LastRowSheet2; row++)
{
    Sheet2Rows.Add(ExcelWksht2.Cells[row, 1].Value);
}

for (int column = 16; column <= LastColumnSheet2; column++)
{
    ColumnDates.Add(ExcelWksht2.Cells[5, column].Value);
}

IEnumerable<string> Names1 = Sheet1Rows;
IEnumerable<string> Names2 = Sheet2Rows;
IEnumerable<DateTime> Dates1 = ColumnDates;

IEnumerable<string> NamesInBoth = Names1.Intersect(Names2);
IEnumerable<string> NamesOnlyInTwo = Names2.Except(Names1);
Debug.Print("NamesInBoth\n==========");

foreach (var n in NamesInBoth)
{
    Debug.Print(n.ToString());

    //Get Row Values
    int rowinsheet1 = (Sheet1Rows.FindIndex(x => String.Compare(x, n) == 0)) + 9;
    int rowinsheet2 = (Sheet2Rows.FindIndex(x => String.Compare(x, n) == 0)) + 9;

    //Get Date Values
    var Sheet1Date = ExcelWksht1.Cells[rowinsheet1, 9].Value.ToString();
    var Sheet2Date = ExcelWksht2.Cells[rowinsheet2, 9].Value.ToString();

    if (Sheet1Date != "No Planned Date" && Sheet2Date != "No Planned Date")
    {
        if (Sheet1Date != null && Sheet2Date != null)
        {
            if (Sheet1Date.ToString() != Sheet2Date.ToString())
            {
                //THIS IS WHERE IM STRUGGLING
            }
        }
        else 
        {
            ((Excel.Range)ExcelWksht2.Cells[rowinsheet2, 1]).EntireRow.Interior.Color = Microsoft.Office.Interop.Excel.XlRgbColor.rgbOrange;
        }
    }  
} 

      

Problem

As shown in the code, I need to figure out a way to construct a loop (?) To check the string date value for all course values ​​in an IEnumerable to give me a date value starting in a 7 day range.

+3


source to share





All Articles