none
Copy Foumula in Excel column C till the data ends in Column B in VB.Net RRS feed

  • Question

  • What would be the procedure to copy formula in Excel column C till the data ends in Column B in VB.Net.

    I am using this code in VB.Net which writes the formula in cell C2. [I don't have any blank cell in Column A and Column B]

    .Range("C2").Formula = "=Sum(A2:B2)"

    I want to copy formula till the data ends in "column C" or "Column A" from Vb.net. I know the code for VBA(Macro)

    Range("C2").Copy Range("C3", Cells(Rows.Count, "B").End(xlUp).Offset(0, 1))

    Any Suggestions on the VB.Net.....

    • Moved by Yang,Chenfei Friday, August 23, 2013 7:16 AM move thread
    Thursday, August 22, 2013 12:13 PM

Answers

  • Hi,

    The code below is you are looking for:

      Microsoft.Office.Interop.Excel.Worksheet sheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
    
        (sheet.Cells[2, 3] as Range).Copy(sheet.get_Range((Range)sheet.Cells[3, 3], ((Range)sheet.Cells[sheet.Rows.Count, 2]).get_End(XlDirection.xlUp).get_Offset(0, 1))); 

    You can get more information from link below:

    http://msdn.microsoft.com/en-us/library/office/dn320445.aspx

    Friday, August 23, 2013 2:13 PM