90 likes | 243 Vues
This guide covers fundamental Visual Basic for Applications (VBA) macros to enhance Excel productivity. Learn to create pop-up message boxes that greet users, display active cell values, and manipulate cell content. The tutorial includes steps to fill selections with fixed values, copy data, and perform calculations such as multiplying cell values. It also introduces conditional statements with practical exercises to change cell formatting based on specific criteria. By mastering these basics, you can automate and streamline various Excel tasks effectively.
E N D
Visual Basic for Application (VBA) Basics 2
Write a macro that … • … uses a popup message box to say Hello. (msgbox ”Hello”) • … writes the contents of the active cell in a message box.(you need: msgbox …; activecell.value) • … fills the selection with your name. (selection.value…) • … fills the selection with the contents of cell A1! (range(”A1”).value)
Write a macro that … • … displays the active workbooks name in a message box. • … puts the workbooks name in the active cell. • … copies contents of the active cell to the one under it. • … displays the active cells value multiplied by 100 in a message box. • … multiplies the active cell by 100 (in place).
Write a macro that … • … multiplies the active cell by the cell on the left, and puts the results into the cell on the right. • Same as above, but this time, display the results in a message box. • … gives a warning in a message box about deleting cell contents, then deletes the contents of the active cell. • … deletes contents from the selection, then changes the background colours to red.
Branching If statementThen True part; Commands if statement is true Else False part; Commands in case statement is false End if If statement1Then True part1; True part1; ElseIfstmnt2 Then True part2; ElseIfstmnt3 Then True part3; Else False part; End if
Exercises for IF conditions • If active cell is empty, change its colour to red. • If the number in the active cell is >10, clear it. • If active cell is < 10, add 1, else clear it. • If active cell is negative, change its colour to red, else make it green.
Exercises for IF conditions • Write a macro that tells us in a message box if the active cell is greater then the one to the right, or not. • Write a macro that tells us in a message box if the active cell is greater than, less than or equal to the one to the right.