In the previous post we have seen, how to read data from excel to VBA. We will see how to write data to Worksheet Cell in Excel VBA.
It is same as reading the data from Excel to VBA. We can use Cell or Range Object to write into a Cell.
The following example will show you how to write the data to Worksheet Cell using Cell Object.
In this example I am writing the data to first Cell of the Worksheet.
Cells(1, 1)="Hello World"
'Here the first value is Row Value and the second one is column value
'Cells(1, 1) means first row first column
In this example I am writing the data to first row and fourth column of the worksheet.
Cells(1, 4)="Hello World"
The following example will show you how to write the data into Worksheet Cell or Range using Range Object.
In this example I am reading the data from first Cell of the worksheet.
'Here you have to specify the Cell Name which you want to read - A is the Column and 1 is the Row
When you are writing the data using Cell or Range object, it will write the data into Active Sheet. If you want to write the data to another sheet, you have to mention the sheet name while writing the data.
The below example is reading the data from Range A5 of Sheet2:
'Here the left side part is sheets to refer and the right side part is the range to read.
In the same way you can mention the workbook name, if you are writing the data to different workbooks.