. Excel VBA Macros for Beginners- Novice Example 1: How To Access The Excel Range And Show The Value Using Message Box While automating most of the Excel Tasks, we need to read the data from Excel spread sheet range and perform some calculations. This example will show you how to read the data from a worksheet range. 'Example 1: How To Access The Excel Range And Show The Value Using Message Box Sub sbExample1 'It will display the A5 value in the message Box MsgBox Range('A5') 'You can also use Cell Object to refer A5 as shwon below: MsgBox Cells(5, 1) 'Here 5 is Row number and 1 is Column number End Sub Excel VBA Macros for Beginners- Novice Example 2: How To Enter Data into a Cell After performing some calculations using VBA, we generally write the results into worksheet ranges. This example will show you how to write the data from VBA to Spread sheet range or cell.
Are you looking for Excel examples? Are you looking for clear explanations that help you master many Excel features quickly and easily? Then this section. 300 Examples. Are you looking. Looking for free Excel training? Are you going for an interview? 3 things to remember before Excel VBA Interview 50 Excel VBA Interview questions or looking for a job? Excel, Access, SQL, VBA, MIS, Reporting and Data Analysts Jobs.
'Example 2: How To Enter Data into a Cell Sub sbExample2 'It will enter the data into B5 Range('B5') = 'Hello World! Using Range' 'You can also use Cell Object as shwon below B6: Cells(6, 2) = 'Hello World! Using Cell' 'Here 6 is Row number and 2 is Column number End Sub Excel VBA Macros for Beginners- Novice Example 3: How To Change The Background Color Of A Particular Range The following example will help you in formatting a cell or range by changing the background color of a range.
![Download Download](https://excelchamps.com//blog/wp-content/uploads/2017/08/use-useful-macro-codes-examples-by-pasting-them-into-vb-editor.png)
We can use ColorIndex property of a Ranger Interior object to change the fill color of a range or cell. 'Example 3: How To Change The Background Color Of A Particular Range Sub sbExample3 'You can set the background color using Interior.ColorIndex Property Range('B1:B5').Interior.ColorIndex = 5 ' 5=Blue End Sub Excel VBA Macros for Beginners- Novice Example 4: How To Change The Font Color And Font Size Of A Particular Range You may need to change the font color of range or cell sometimes. We can differentiate or highlight the cell values by changing the text color of range in the worksheet. The following method will use the font ColorIndex property of a range to change the font color. 'Example 4: How To Change The Font Color And Font Size Of A Particular Range Sub sbExample4 'You can set the background color using Interior.ColorIndex Property Range('B1:B10').Font.ColorIndex = 3 ' 3=Red End Sub Excel VBA Macros for Beginners- Novice Example 5: How To Change The Text To Upper Case Or Lower Case This example will help you to change the text from lower case to upper case.
We use UCase Function to do this. If you wan tot change the text or string from upper case to lower case, we can use LCase function. 'Example 5: How To Change The Text To Upper Case Or Lower Case Sub sbExample5 'You can use UCase function to change the text into Upper Case Range('C2').Value = UCase(Range('C2').Value) 'You can use LCase function to change the text into Upper Case Range('C3').Value = LCase(Range('C3').Value) End Sub Excel VBA Macros for Beginners- Novice Example 6: How To Copy Data From One Range To Another Range This example will help you to copy the data from one particular range to another range in a worksheet using VBA. 'Example 6: How To Copy Data From One Range To Another Range Sub sbExample6 'You can use Copy method Range('A1:D11').Copy Destination:=Range('H1') End Sub Excel VBA Macros for Beginners- Novice Example 7: How To Select And Activate Worksheet This example will help you to select one particular worksheet.
To activate one particular sheet we can use Activate method of a worksheet. 'Example 7: How To Select And Activate Worksheet Sub sbExample7 'You can use Select Method to select Sheet2.Select 'You can use Acctivate Method to activate Sheet1.Activate End Sub Excel VBA Macros for Beginners- Novice Example 8: How To Get The Active Sheet Name And Workbook Name 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 Excel VBA Macros for Beginners- Novice Example 9: How To Add New Worksheet And Rename A Worksheet and Delete Worksheet We can Name property of worksheet to rename or change the worksheet name. We can use Add method of worksheets to add a new worksheet. Use Delete method to delete a particular worksheet. 'Example 9: How To Add New Worksheet And Rename A Worksheet and Delete Worksheet Sub sbExample9 'You can use Add method of a worksheet Sheets.Add 'You can use Name property of worksheet ActiveSheet.Name = 'Temporary Sheet' 'You can use Delete method of a worksheet Sheets('Temporary Sheet').Delete End Sub Excel VBA Macros for Beginners- Novice Example 10: How To Create New Workbook, Add Data, Save And Close The Workbook The following examples will help you to adding some data, saving the file and closing the workbook after saving the workbook. Hi, Hope you are doing good!
Your website its really very good and helpful. I was trying to create an account at your website however, could not find an option to register. Please do help me out with path to create an account. I am learning how to create VBA Excel Macros. I have a question, no idea if this is the right way to ask.
TransactionID Debit Credit NBC0010 51,878 0 NBC0016 34,788 0 NBC0033 42,356 0 NBC0036 54,713 0 NBC0040 0 33,584 NBC0041 49,986 0 NBC0045 0 49,986 NBC0046 0 56,525 NBC0048 0 40,434 NBC0050 56,898 0 NBC0052 0 56,898 above is my data i want to highlight those debit transaction id which have equal credit amount. I am trying to solve it with IF condition. Awaiting for your reply. Thanks & Regards Atif Khan. Hi PNRao I am working on Excel to blink cells in a row, what i actually want is the text in a cell only to blink. I have this code which i got from the web and made some modification.
Hi Usama, If we want to change any text to either upper case letters or lowercase letters we using function UCase and LCase. Please run the macro for better understand. Here is the example. Lets say Range(“C2″)=”Analysistabs” in worksheet.
To Convert to upper case: Range(“C2”).Value = UCase(Range(“C2”).Value) Range(“C2”).Value=UCase(“Analysistabs”) Output: Range(“C2”).Value=ANALYSISTABS To Convert to lower case: Range(“C2”).Value = LCase(Range(“C2”).Value) Range(“C2”).Value=LCase(“Analysistabs”) Output: Range(“C2”).Value=analysistabs Hope you understand the macro.