Excel Vba Macros For Beginners
Excel Vba Macros For Beginners
understand and learn the basics of VBA to deal with Excel Objects. Learning Basic Excel VBA
By Examples is the easiest way to understand the basics of VBA to deal with Excel Objects, in
this tutorial we will not covering any programming concepts, we will see how to access the
different Excel Object using VBA.
In this topic:
1. How To Access The Excel Range And Show The Value Using Message Box
2. How To Enter Data into a Cell
3. How To Change The Background Color Of A Particular Range
4. How To Change The Font Color And Font Size Of A Particular Range
5. How To Change The Text To Upper Case Or Lower Case
6. How To Copy Data From One Range To Another Range
7. How To Select And Activate Worksheet
8. How To Get The Active Sheet Name And Workbook Name
9. How To Add New Worksheet And Rename A Worksheet and Delete Worksheet
10. How To Create New Workbook, Add Data, Save And Close The Workbook
11. How To Hide And Unhide Rows And Columns
12. How To Insert And Delete Rows And Columns
13. How To Set The Row Height And Column Width
14. How To Merge and UnMerge Cells
We can use Name property of a active sheet to get the worksheet name. We can use name
property of active workbook to get the name of the active workbook.
'Example 8: How To Get The Active Sheet Name And Workbook Name
Sub sbExample8()
'You can use ActiveSheet.Name property to get the Active Sheet name
MsgBox ActiveSheet.Name
'You can use ActiveWorkbook.Name property to get the Active Workbook name
MsgBox ActiveWorkbook.Name
End Sub
Sub sbExample10()
'You can use Add method of a Workbooks
Workbooks.Add
'You can use refer parent and child object to access the range
ActiveWorkbook.Sheets("Sheet1").Range("A1") = "Sample Data"
'It will save in the deafult folder, you can mention the full path as
"c:\Temp\MyNewWorkbook.xls"
ActiveWorkbook.SaveAs "MyNewWorkbook.xls"
ActiveWorkbook.Close
End Sub
End Sub
Example 13: How To Set The Row Height And Column Width
We can set the row height or column width using VBA. The following example will show you how
to do this using VBA.
'Example 13: How To Set The Row Height And Column Width
Sub sbExample13()
'You can use Hidden Propery of Rows
Rows(12).RowHeight = 33
Columns(5).ColumnWidth = 35
End Sub