VBA Flashcards
For Loops
For each i in j (step (x)) %step is optional
….
next i
For i to 10 (step x)
….
next i
If loops
If not A is nothing then %if A is not empty
…..
end if
if .... then ... else if .... then .... end if
Do while loop
Do [while condition] [statements] [exit do] [statement] loop
Do until loop
Do [until condition] [statements] [exit do] [statements] Loop
Select case loop
select case TESTEXPRESSION [case EXPRESSIONLIST 1] [statement 1] [case EXPRESSIONLIST 2] [statement 2] .... [case else] [else statement] end select
Select the cells contains constant(or contains formula, or is empty)
Set object1=selection.specialcells(xlConstants,xlNumbers)
%object1 equals the range of cells that has number and is constant
Set object2=selection.specialcells(xlCellTypeBlanks)
%object2 equals the range of cells that is empty
Set object3=selection.specialcells(xlFormulas,xlNumbers)
%object3 equals the range of cells that contains number and formula
decide whether a cell is empty or not
If IsEmpty(cell(i,j).value) then
….
end if
select the use range
ActiveSheet.UsedRange
With Statement
With Activecell.font .Bold= .Color= .Name= .Size= .Italic= End With
(same object is select multiple times)