VBA basic Operation
In
any programming language read and write are basic operations in previous blog
we had written about hello world and in this blog discussed more about VBA
Programming language. But before
perform basic operations using VBA at first we will learn how to select cell
from excel.
Select Range and Write HelloWorld in VBA
As
we know that excel is basically a matrix which contains rows and columns and we
perform our operations on these rows and columns. In Excel these rows and
columns in a combined way are called as cell, hence basically here we performing
our operation on cell and to perform operation on a cell we first select a
cell, to select a cell we use Range
function.
Syntax
:
Range(“A1”) Or Range(“A1:A5”)
Example
:
Code:
Sub basicVbaTut()
ThisWorkbook.Sheets("Sheet1").Range("A1").Value
= "Hello world"
End Sub
Output:
Read a
Cell in VBA
In
VBA to read information from a cell we have to at first select a cell and after
selecting a cell we have to operand on it. And to select a cell we have to use
this syntax.
Syntax
:
Cell([row
index],[column index])
Example
:
In
this example we read elements of first cell which is written in previous
program.
Code
:
Sub
basicVbaTut()
MsgBox Cells(1, 1)
End
Sub
OutPut :
Comments
Post a Comment