• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/14

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

14 Cards in this Set

  • Front
  • Back

VBA




SUB NameRange ()



formula



END SUB

Running, Stepping into, Stopping Macros

F5 = Runs Macro



F8 = Steps into Macro



STOP = add into Macro to stop operation at certain point

RANGE OBJECT

= Range (A1:C5) = "quotes if text"




*This tells excel where to insert ""


Code for Range Object

Sub InsertRange()



Range("a1:a6") = "hello"



End Sub



*numbers do not need text


CELL OBJECT



Sub insertCellObject()



Range(Cells(1, 1), Cells(6, 6)) = "GO AWAY"



Cells(3, 1) = 5



End Sub



*rows come first, then columns

Using Range Object in conjunction with Cells

You can type in a range object using cells



Range(Cells(1, 1), Cells(6, 6)) = "GO AWAY"



OR



A range using the exact object



Range("A1:F6") = "GO AWAY"



NAMING A RANGE

You can name a range and use this in equation



Sub ameliasRange()


Range("ameliasRange") = 47


End Sub

In VBA - when excel


Capitalises


Capitalises - this means that excel has predefined it and you can not mess with it eg date + hit enter = Date

FOR & NEXT




VARIABLES = x




For x = 1 To 10



Cells(x, 1) = x + x * 5 [in the first column, moving down x rows]

Cells(x, 2) = Date + 1 * x


[in the second column, moving down x rows]

Cells(x, 3) = "hohoho"



Next x



End Sub




*loops until x = 10,calculate outcome mathimatically


FOR & NEXT

*starting at x = 2, so that you can avoid Headers. ie It wont overwrite



* Look at the x operation,


=x+1 = adds 2 to x


=x+x*1 = adds =2+2*" = 5

IF & THEN

Sub If_Next_Else()



For X = 3 To 10


Cells(X, 1) = Date + 2
Cells(X, 2) = X + 5 * X


If Cells(X, 2) > 50 Then

Cells(X, 3) = "WIN"

End If



Next X



End Sub

IF & THEN & ELSE

Sub If_Next_Else()



For x = 3 To 10



Cells(x, 1) = Date + 2
Cells(x, 2) = x + 5 * x


If Cells(x, 2) > 50 Then

Cells(x, 3) = "WIN"


Else: Cells(x, 3) = "lost"
End If



Next x



End Sub

Other VBA Tips



Using VBA

-Ctrl J - Brings up List Property/Methods



-Comment Block and Uncomment Block. You can comment out lines of code and and they are skipped over



-ToggleBreakpoint F9



-Object Browser F2 / F7 gets you back to code



-Property Window F4 (propertys of the worksheet)

Create Message Box

Sub Message_Box()


MsgBox "Hello World!", vbOKOnly, "Howdy"
End Sub




*The message, the options, the header of msg