You are on page 1of 4

Elisa = 1997

Elisa: Variable
= assigns a value to variable
1997: value (value of the variable 1997)

Cells(x,y) = Elisa

Cells(x,y): celula x,y


= assigns value to variable
Elisa: value of the variable

Elisa = “Bannwart”
Elisa: Variable
= assigns value of the variable
“Bannwart”: value is text “Bannwart”

Concatenated:
- Use +
- Junta duas coisas
- Eg: 3 + 3 = 33

Option Explicit:
- This ensures all variables must be defined
- This is performed by a DIM statement

Dim:
- Integer:
o
- String

Pintar de amarelo celulas da linha 2 a 5 e coluna de 3 em 3:

Sub yellowLoop()

colNum = 3

For rowNum = 2 To 5

 '-----------------------------
  'Set back to yellow
  '-----------------------------
  'This assigns a value to the
  'ColorIndex property of the
  'Interior property of the
  'Excel cell at row equal to
  'the value of variable rowNul,
  'column equal to the value
  'of variable colNum.
  'The value is the number 6

  Cells(rowNum, colNum).Interior.ColorIndex = 6
  colNum = colNum + 3
Next rowNum

End Sub

Mesma coisa + nomes

Sub yellowLoop()

colNum = 3

For rowNum = 2 To 5

 If rowNum = 2 Then


    Cells(rowNum, colNum) = "Andy"
  ElseIf rowNum = 3 Then
    Cells(rowNum, colNum) = "Bill"
  ElseIf rowNum = 4 Then
    Cells(rowNum, colNum) = "Chloe"
  ElseIf rowNum = 5 Then
    Cells(rowNum, colNum) = "David"
  End If

  Cells(rowNum, colNum).Interior.ColorIndex = 6
  colNum = colNum + 3
Next rowNum

End Sub

Pintar de Vermelho celulas da linha 12 a 15 e coluna 9 a 13

Sub redLoop()

'Initialise colNum
colNum = 13

For rowNum = 12 To 15
  Cells(rowNum, colNum).Interior.ColorIndex = 3
  colNum = colNum - 1
Next rowNum

End Sub
colNum = 3

For rowNum = 15 To 19

If rowNum = 15 Then

Cells(rowNum, colNum) = "all"

ElseIf rowNum = 16 Then

Cells(rowNum, colNum) = "boys"

ElseIf rowNum = 17 Then

Cells(rowNum, colNum) = "cry"

ElseIf rowNum = 18 Then

Cells(rowNum, colNum) = "depply"

ElseIf rowNum = 19 Then

Cells(rowNum, colNum) = "everyday"

End If

Cells(rowNum, colNum).Interior.ColorIndex = 3

colNum = colNum + 3

Next rowNum

Pintar de azul as celulas pulando 5 linhas 2 colunas (linha 9-19; coluna 3-7)

Sub blueLoop()
For rowNum = 9 To 19 Step 5

  For colNum = 3 To 7 Step 2


     
    Cells(rowNum, colNum).Interior.ColorIndex = 5
     
  Next colNum

Next rowNum

End Sub

'ColorIndex values:
' 0 = none
' 1 = black
' 2 = white
' 3 = red
' 4 = green
' 5 = blue
' 6 = yellow

1) 10 lines of code : YOU explain in English what they do


2) I give you instructions YOU code VBA to do what I ask

3) Loops - 4 of them

Black Loop = hard

sub blackLoop()

End Sub

You might also like