FULLY QUALIFING VARIABLES Flashcards
How do you fully qualify the worksheet and wb objects?
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets (“Sheet1”)
Write code where you are wanting to include the last row of data.
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, “A”).End(xlUp).Row
What is the purpose of the For….Next statement?
It repeats a block of statements a specific number of times:
It will use a Counter Variable whose value can be either increased or decreased with each repetition of the loop.
Which VBA function references a single cell at a time?
Cells function
VBA code: Worksheets(“Sheet1”).Cells - is referencing what?
Every single cell in the entire sheet (the only time it doesn’t reference a single cell).
What cell does this code reference: Worksheets(“Sheet1”).Cells(3)?
C1
Write VBA using cell reference for D15.
Worksheets(“Sheet1”).Cells(15,4)
You can using the actual column letter - do so using cell function for D15:
Cells(15, “D”)
Are you allowed to use the column letter inside of a cell function?
yes
Is it a good idea to use a loop with a Range function?
No - because the references for cells aren’t numbers.
What would be a workaround for using loops and the Range function?
You can embed the Cells functions inside of a Range Function.
What is the value of using the Cell function inside of a Range function?
You can write dynamic code using Loops - using just the Range function does not do this.