A simple example of how you can add, automatically, the data in an Excel worksheet
In some cases, it is useful to add, automatically, the data in an Excel worksheet. The following example shows how to do it.
Code:
Sub LoadData()
' Rename the sheets
Sheet1.Name = "Balance"
' Active Sheet1
Sheet1.Activate
' Add header
Sheet1.Cells.Item(1, 1) = "Description"
Sheet1.Cells.Item(1, 2) = "Date"
Sheet1.Cells.Item(1, 3) = "Amount"
'Add informations
Sheet1.Cells.Item(2, 1) = "Hosting"
Sheet1.Cells.Item(2, 2) = "19/06/2011"
Sheet1.Cells.Item(2, 3).Value = 80
'Add informations
Sheet1.Cells.Item(3, 1) = "Web site"
Sheet1.Cells.Item(3, 2) = "23/06/2011"
Sheet1.Cells.Item(3, 3).Value = 1900
'Add informations
Sheet1.Cells.Item(4, 1) = "Deploy and Setup"
Sheet1.Cells.Item(4, 2) = "23/06/2011"
Sheet1.Cells.Item(4, 3).Value = 120
' Calculate the total
Sheet1.Cells.Item(6, 2) = "TOTAL"
Sheet1.Cells.Item(6, 3).Formula = "=Sum(C2:C4)"
Sheet1.Cells.Item(6, 2).Font.Size = 14
Sheet1.Cells.Item(6, 2).Font.Size = 14
End Sub
Result: