VBA and Microsoft Excel

VBA can be used to complete a wide range of tasks in Microsoft excel. Some of the most useful and populate are writing and read to cells. This allows your code and scripts to interact with workbooks and calculations in excel.

Writing to Excel Cells

Sub writeToCells()

    Cells.Range("A1").Value = "Engine"
    Cells(1, 2).Value = "Bumper"
End Sub

In Excel:

This creates the following on the selected sheet.

Reading from Excel Cells

Sub readFromCells()

    Dim name As String

    name = Cells.Range("A1").Value
    MsgBox name

End Sub

In Excel:
This creates the following output. 

Selecting different sheets 

Sometimes you may need to write to a range of sheets. This example shows how to achieve that. The same method is used for reading the data across sheets.

Sub writeSheets()

    Sheets("Sheet2").Range("A5") = "Hello"
End Sub

In Excel:


Related Sections

Python - Learn the python from the basics up. This fast track example code course will get you creating powerful python programs in no time.

Must Read Articles

VBA and Microsoft Excel - Getting the most out of excel with VBA programming
VBA and Microsoft Word - Getting the most out of word with VBA programming
Application Object - Using the applications features in your code.
Installing VBA and First Program - What do you need to start using visual basic application VBA.