Sie sind auf Seite 1von 1

VBA for Excel Cheat Sheet

by guslong via cheatography.com/1345/cs/510/

VBA data types deleting, moving, copying (VBA) (cont) String functions

Type Desc​rip​tion Delete a worksheet InStr ([start], "​str​ing​", Returns position of

Worksh​eet​s("S​hee​t2").Delete "​wha​t_t​o_f​ind​") string within a string


Variant any data type
StrCon​v("s​tri​ng", converts string to
Integer (2 bytes) integer Execute a formula calcul​ation in a range
vbProp​er|​Upp​er|​Low​er proper​|up​per​|lower
Long (4 bytes) integer Range(​"​A1:​A3").Fo​rmula = 2*2/6 Case) case
Single (4 bytes) floating point
Use RANGE to select single cells. Left ("st​rin​g", x) Return specified
Double (8 bytes) floating point
Len ("st​rin​g") Return length of
String non-nu​meric data Iterate through a selection string

Object any object reference Dim cell As Range Trim ("st​rin​g") Trims string of
For Each cell In Selection leading and trailing
Date a date
... spaces
Boolean True / False
Next cell Split(​"​str​ing​", "​,") Split string by
Byte 1-255
delimiter e.g. comma
Control structures VBA Val("st​rin​g") Return numerical
Cell selection
Do ... Until Loop part only
select a single cell Do [Until condition] StrCom​p("s​trA​", Compare two strings
Range(​"​A1").Select ... "​str​B", (0=true)
Loop vbText​Com​pare)
select a contiguous range
Do ... While Loop
Range(​"​A1:​G5").Select Do [While condition] VBA inform​ation functions
select a non-co​nti​guous range ...
IsArray
Loop
Range(​"​A1:​G5,​J10​:J1​5").S​elect
For...Next Loop IsEmpty
offset syntax (move from A1 to A2) For counter = start To end [Step s] IsError
Range(​"​A1").Of​fse​t(1​,0).Select ...
IsMissing
Next [counter]
select down to first empty cell IsNumeric
Range(​Sel​ection, "​WIT​H" syntax IsNull
Select​ion.En​d(x​lDo​wn)​).S​elect
IsObject
With Worksh​eet​s("S​hee​t1")
set a cell's value .Rows
Range(​"​A1").Value = i .Columns
...
End With
deleting, moving, copying (VBA)
The "​wit​h" constr​uction provides a shorthand
Delete entire row
way of accessing many properties and
Rows("2​"​).D​elete
methods of the same object.
Delete entire column

Column​s("B​"​).D​elete

Copy / paste a range with destin​ation

Range(​"​A1:​B6").Copy
Destin​ati​on:​=Ra​nge​("A1​")

Clear a range

Range(​“D:​D").C​lear

By guslong Published 13th August, 2012. Sponsored by Readability-Score.com


cheatography.com/guslong/ Last updated 5th June, 2014. Measure your website readability!
Page 1 of 1. https://readability-score.com