Download presentation
Presentation is loading. Please wait.
1
Writing VBA Macros Record a new Macro, recording only the name, shortcut and description Stop recording Open macro for editing and enter VB code Test
2
Moving around the Spreadsheet To move the cursor to a particular cell (starting point) Range(“A4”).select Range(“NamedCell”).select This is now the “Active Cell”
3
Referencing a Cell from ActiveCell ActiveCell.offset (R,C) e.g. ActiveCell.offset(0,-1) refers to the cell one to the left of the ActiveCell
4
To place information from a VB variable into a spreadsheet Range(“D4”) = TaxRate Range(“Result”) = Sum ActiveCell = Salary * Rate ActiveCell.offset(12,0) = totalCost ActiveSheet.Cells(11,9) = Total Worksheets(“MySheet”).Cells(1,1) = title Sheet2.cells(1,3) = Title 'Refers to sheet 2 row1,column 3
5
To input from a spreadsheet to variable Amount = ActiveCell Amount = ActiveCell.Offset(0,-3) Amount =ActiveSheet.Cells(9,1) 'current sheet Row 9, column 1
6
Loops Do until ActiveCell.offset(Row, 0) = “” 'put your actions here Row = Row +1 Loop
7
Other Features Assigning Macros to Buttons Rather than using Ctrl + Character all the time More handy to have a button Insert Shapes Draw button Right Click on the button Assign macro Any of the VB commands can be used InputBox ActiveCell = InputBox(“Enter you name”,”Namebox”) Msgbox
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.