or   Register or Register today to make and share your own cheat sheets! (Why Join?)

Cheatography Login

Join Us!

Not a Cheatographer? Register here!

Social Media

You can login to or register with Cheatography using your Facebook or Twitter account!

Why Join Cheatography?

Make and share cheat sheets!
Join a great community of Cheatographers and add your very own contributions.

Save your favourites!
Quick access to your most loved cheat sheets.

Fewer ads!
Members see no ads on the site.

Coming soon ...
Requests, ratings and more!

Why Join Cheatography?

Make and share cheat sheets!
Join a great community of Cheatographers and add your very own contributions.

Save your favourites!
Quick access to your most loved cheat sheets.

Fewer ads!
Members see no ads on the site.

Coming soon ...
Requests, ratings and more!

VBA for Excel Cheat Sheet by guslong

Comments   |   Add a Comment   |   PDF Download   |   Find:

VBA data types

Type Desc­rip­tion
Variant any data type
Integer (2 bytes) integer
Long (4 bytes) integer
Single (4 bytes) floating point
Double (8 bytes) floating point
String non-nu­meric data
Object any object reference
Date a date
Boolean True / False
Byte 1-255

Cell selection

select a single cell
Range(­"­A1").Select
select a contiguous range
Range(­"­A1:­G5").Select
select a non-co­nti­guous range
Range(­"­A1:­G5,­J10­:J1­5").S­elect
offset syntax (move from A1 to A2)
Range(­"­A1").Of­fse­t(1­,0).Select
select down to first empty cell
Range(­Sel­ection, Select­ion.En­d(x­lDo­wn)­).S­elect
set a cell's value
Range(­"­A1").Value = i

deleting, moving, copying (VBA)

Delete entire row
Rows("2­"­).D­elete
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
Delete a worksheet
Worksh­eet­s("S­hee­t2").Delete
Execute a formula calcul­ation in a range
Range(­"­A1:­A3").Fo­rmula = 2*2/6

Use RANGE to select single cells.

 

Iterate through a selection

Dim cell As Range
For Each cell In Selection
...
Next cell

Control structures VBA

Do ... Until Loop

Do [Until condition]
...
Loop

Do ... While Loop
Do [While condition]
...
Loop

For...Next Loop
For counter = start To end [Step s]
...
Next [counter]

"WITH" syntax

With Worksh­eet­s("S­hee­t1")
.Rows
.Columns
...
End With

The "­wit­h" constr­uction provides a shorthand way of accessing many properties and methods of the same object.

 

String functions

InStr ([start], "­str­ing­", "­wha­t_t­o_f­ind­") Returns position of string within a string
StrCon­v("s­tri­ng", vbProp­er|­Upp­er|­Low­erCase) converts string to proper­|up­per­|lower case
Left ("st­rin­g", x) Return specified
Len ("st­rin­g") Return length of string
Trim ("st­rin­g") Trims string of leading and trailing spaces
Split(­"­str­ing­", "­,") Split string by delimiter e.g. comma
Val("st­rin­g") Return numerical part only
StrCom­p("s­trA­", "­str­B", vbText­Com­pare) Compare two strings (0=true)

VBA information functions

IsArray
IsEmpty
IsError
IsMissing
IsNumeric
IsNull
IsObject

Favourited by 2 Members:

The_Frail akipta

Comments

No comments yet. Add yours below!

Add a Comment

Comment:

Contents

VBA for Excel (beginners level stuff)

Column Content Comments Author Updated
- VBA for Excel Cheat Sheet guslong 13 Aug 12
1 VBA data types 0 guslong 8 Aug 12
Cell selection 0 guslong 13 Aug 12
deleting, moving, copying (VBA) 0 guslong 13 Aug 12
2 Iterate through a selection 0 guslong 13 Aug 12
Control structures VBA 0 guslong 13 Aug 12
"WITH" syntax 0 guslong 13 Aug 12
3 String functions 0 guslong 13 Aug 12
VBA information functions 0 guslong 13 Aug 12