gabriel-t
8/9/2017 - 9:29 PM

1. Getting Started

Getting Started

Worksheets("WorksheetName").Add After:=Worksheets("WorksheetName")

Range("A1:B7").Font.Name = "Times New Roman"
Range("A1","B7").Font.Name = "Times New Roman"

'Worksheets is the Object
'.Add is the Method
'After:= is the Parameter for .Add. The value for the parameter cannot have space in between.
'.Font.name is the Property
'Change size of a range of cells, but keep the starting position
Range("A1").Resize(2,2).Select
'Select cells A1:B2

'Resize value has to be >= 1. A workaround is to use Offset and Resize together.
Range("C3").Resize(-2,-2).Select
'Error
Range("C3").Offset(-1,-1).Resize(2,2).Select
'Select cells B2;C3
1) Developer> Code> Record Macro
2) Give a name. Store marco in somewhere.
3) Perform your action.
4) Devloper> Code> Stop Recoding

Delete Marco
1) Developer> Marco
2) Delete*
*If you get an error message about not being able to delete marcos while Personal work book is hidden, click Cancel on the dialogue box. From Excel, click on the View ribbon. Locate Window panel and click unhide. Now delete and save your Personal workbox in the editor again.
'Selecting a new range of cells based on a starting position.

Range("A1").Offset(1,2).Select
'The above code will select C2 (Move one row from cell A1 and two column from cell A2)

Range("A1").Offset(1).Select
Range("A1").Offset(,1).Select
'You can fill in row position and leave column position blank, or vice versa.

Range("A1").Offset(-1,-1).Select
'You can also specify negative number
Sub SubName()
  MsgBox "Text"
End Sub
'Subroutines are a chunk of code that does a particular job
'Subroutines can't contain spaces
'Subroutines can't start with number, only alphabetical characters
'Subroutines can't contain full stops, #, $, %, &, !
  
Sub ActiveCell_Example ()
  Range(ActiveCell, "D6").Select
End Sub
'Highlight cells from active cell to D6