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.
50+ Project Management Templates Pack
Excel PowerPoint Word
Advanced Project Plan & Portfolio Template
Ultimate Project Management Template
20+ Excel Project Management Pack
20+ PowerPoint Project Management Pack
10+ MS Word Project Management Pack
Write Data to Worksheet Cell in Excel VBA – Solution(s):
It is same as reading the data from Excel to VBA. We can use Cell or Range Object to write into a Cell.
Write Data to Worksheet Cell in Excel VBA – An Example of using Cell Object
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.
Sub sbWriteIntoCellData() 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 End Sub
In this example I am writing the data to first row and fourth column of the worksheet.
Sub sbWriteIntoCellData1() Cells(1, 4)="Hello World" End Sub
Write Data to Worksheet Cell in Excel VBA – An Example of using Range Object
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.
Sub sbRangeData() Range("A1")="Hello World" 'Here you have to specify the Cell Name which you want to read - A is the Column and 1 is the Row End Sub
Write Data to Worksheet Cell in Excel VBA – Specifying the Parent Objects
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:
Sub sbRangeData1() Sheets("Sheet2").Range("A5")="Hello World" 'Here the left side part is sheets to refer and the right side part is the range to read. End Sub
In the same way you can mention the workbook name, if you are writing the data to different workbooks.
|Excel VBA Reference||Project Management Reference|