VBA Data Types VBA Interacting With User Referencing Workbooks/Worksheets/Ranges
String Message Box Workbooks Used to hold text Msgbox “Hello world” Workbook that contains code: Long User Input ThisWorkbook Long integer (whole numbers). -2,147,483,648 to usrInput = InputBox(“Please Enter Your Name”) Using the Active Workbook: Active Workbook 2,147,483,647 Using Numbered Index: Integer Workbooks(1) Short integer (whole number). -32,768 to 32,767 Comparison Operators Using Workbook Name: Boolean Greater Than / Greater Than or Equal Workbooks(“myWkbk”) True or False Greater Than : > Worksheet Boolean Greater Than or Equal: >= Using the Active Worksheet: True or False Less Than / Less Than or Equal ActiveSheet Date Less Than : < Using the Selected Worksheet: Less Than or Equal: <= Windows.SelectedSheets Holds date data types. 1/1/100 to 12/31/9999 Single/Double Equal / Not Equal Using Numbered Index: Equal : = Worksheets(1) Used to hold values with decimals Not Equal: <> Using Worksheet Name: Variant Worksheets(“myWksht”) Catch all data type. When an explicit data type is not Range declared, variant type is assigned Reference Single Cell: Logical Operators Or Range(“A1”) True Or True = True Refernce Multiple Adjacent Cells: VBA Common Operations (Required syntax in bold) True Or False = True Range(“A1:C5”) If Statement False Or False = False Reference Multiple Non Adjacent Cells If numGrade > 90 Then And Range(“A1:A5, C1:C5”) letterGrade = “A” True And True = True Using a Named Range ElseIf numGrade > 80 Then letterGrade = “B” True And False = False Range(“myRange”) Else False And False = False Cells letterGrade = “F” Not Refernce All Cells End If Not True = False Worksheet.Cells Not False = True Rererence Cells with one Parameter Cells(3) = “C1” For … Next Loop Reference Cells With Two Parameters For x=0 to 49 Cells(3,3) = “C3” ‘Loop Over Code Commenting Code Cells(3, “E”) = “E3” Next x Single Line Comment For Each … Next Loop Single line comments are created by For Each Item In Selection using an apostorpher (‘) at the beginning of a line Useful Tips Item.Offset(0, 1) = Item * 2 Next With … End With Do … Loop While Msgbox “This line of code will execute” With ThisWorkbook.Worksheets(1) Do ‘Msgbox “This line of code will execute” .Range(“A1”)=Month .Range(“A1”).Offset(Item,0) = Item Multi Line Comments End With Loop While myBool = True View -> Toolbars -> Edit OffSet Do While … Loop For x=0 to 100 Do While myBool=True .Range(“A1”).Offset(x,0) = Rnd .Range(“A1”).Offset(Item,0) = Item Next x Loop