VB.NET - Excel - How to execute autofill programmatically
Example that shows how to copy formula definition down to multiple cells below in the same column
- same as double click in the bottom right corner in Excel
' check if file exists
Dim fileTest As String = "C:\Temp\ExcelTest\test.xlsx"
If File.Exists(fileTest) Then
File.Delete(fileTest)
End If
Dim oExcel As Object
oExcel = CreateObject("Excel.Application")
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
oBook = oExcel.Workbooks.Add
oSheet = oExcel.Worksheets(1)
oSheet.Name = "Test Name"
' add same values to cells in column a and b
oSheet.Range("A1").Value = "2"
oSheet.Range("B1").Value = "4"
oSheet.Range("A2").Value = "33"
oSheet.Range("B2").Value = "21"
oSheet.Range("A3").Value = "42"
oSheet.Range("B3").Value = "32"
' create formula
oSheet.Range("C1").Formula = "=SUM(A1:B1)"
' copy this formula down using autofill
oSheet.Range("C1").AutoFill(oSheet.Range("C1:C3"))
oBook.SaveAs(fileTest)
oBook.Close()
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
watch this example on YouTube:
Great! Thanks
ReplyDeleteHow To Do - Ms Sql C Excel Access: Vb.Net - Excel - How To Execute Autofill Programmatically >>>>> Download Now
ReplyDelete>>>>> Download Full
How To Do - Ms Sql C Excel Access: Vb.Net - Excel - How To Execute Autofill Programmatically >>>>> Download LINK
>>>>> Download Now
How To Do - Ms Sql C Excel Access: Vb.Net - Excel - How To Execute Autofill Programmatically >>>>> Download Full
>>>>> Download LINK H4