none
How can I use an Int32 to determine the end of an excel autofill range? RRS feed

  • Question

  • Hello. My code is below. I have not been able to figure out how to use an int to set the end of a range. Is this possible? if so can you help me figure out how?

    The question mark represents whatever the column is which is the number of school days-1. So if there is 186 school days, I suppose it would end 185 columns to the right, landing at GF2.

                //get school day number as string then convert to int
                var cellValue = (oSheet.Cells[7, 1] as Microsoft.Office.Interop.Excel.Range).Value2;
                Int32.TryParse(cellValue.ToString(), out Int32 numSchoolDays);
    
                //row column test
                Microsoft.Office.Interop.Excel.Range workdayFill;
                workdayFill = oSheet.get_Range("D2");
                workdayFill.AutoFill(oSheet.get_Range("D2", ?));
    I tried workdayFill.AutoFill(oSheet.get_Range(oSheet.Cells[2, 4], oSheet.Cells[2, numSchoolDays])); but I got the error"Object does not contain a definition for get range".


    • Edited by _Sniffles_ Thursday, July 26, 2018 10:12 PM Forgot what I tried, closest I came to getting it to work.
    Thursday, July 26, 2018 10:04 PM

Answers

  • Hello _sniffles_,

    What about this code?

    workdayFill.AutoFill(oSheet.Range[oSheet.Cells[2, 4], oSheet.Cells[2, numSchoolDays]]);

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by _Sniffles_ Friday, July 27, 2018 3:03 AM
    Friday, July 27, 2018 2:15 AM

All replies

  • Hello _sniffles_,

    What about this code?

    workdayFill.AutoFill(oSheet.Range[oSheet.Cells[2, 4], oSheet.Cells[2, numSchoolDays]]);

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by _Sniffles_ Friday, July 27, 2018 3:03 AM
    Friday, July 27, 2018 2:15 AM
  • Terry! you are a genius! Thank you : D 
    Friday, July 27, 2018 3:03 AM