You are on page 1of 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 Description Execute a formula calculation in a range InStr ([start], "string", Returns position of

Variant any data type Range("A1:A3").Formula = 2*2/6 "what_to_find") string within a string

Integer (2 bytes) integer Use RANGE to select single cells. StrConv("string", converts string to
vbProper|Upper|Lower proper|upper|lower
Long (4 bytes) integer
Case) case
Iterate through a selection
Single (4 bytes) floating point
Left ("string", x) Return specified
Dim cell As Range
Double (8 bytes) floating point
For Each cell In Selection Len ("string") Return length of
String non-numeric data ... string
Object any object reference Next cell Trim ("string") Trims string of
Date a date leading and trailing
Control structures VBA spaces
Boolean True / False
Do ... Until Loop Split("string", ",") Split string by
Byte 1-255
delimiter e.g. comma
Do [Until condition]
... Val("string") Return numerical
Cell selection
Loop part only
select a single cell Do ... While Loop StrComp("strA", Compare two strings
Range("A1").Select Do [While condition] "strB", (0=true)
select a contiguous range ... vbTextCompare)
Range("A1:G5").Select Loop
For...Next Loop
select a non-contiguous range VBA information functions
For counter = start To end [Step s]
Range("A1:G5,J10:J15").Select
... IsArray
offset syntax (move from A1 to A2) Next [counter] IsEmpty
Range("A1").Offset(1,0).Select
IsError
select down to first empty cell "WITH" syntax
Range(Selection, IsMissing
With Worksheets("Sheet1")
Selection.End(xlDown)).Select IsNumeric
.Rows
set a cell's value .Columns IsNull
Range("A1").Value = i ... IsObject
End With
deleting, moving, copying (VBA)
The "with" construction provides a shorthand
Delete entire row way of accessing many properties and
Rows("2").Delete methods of the same object.

Delete entire column


Columns("B").Delete

Copy / paste a range with destination


Range("A1:B6").Copy
Destination:=Range("A1")

Clear a range
Range(D:D").Clear

Delete a worksheet
Worksheets("Sheet2").Delete

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


cheatography.com/guslong/ Last updated 13th August, 2012. Measure your website readability!
Page 1 of 1. https://readability-score.com

You might also like