Excel VBA IF statement and SELECT CASE

Thanks! Share it with your friends!


This video shows some techniques that are vital when you write VBA code. Firstly it shows you how to use the InputBox function to ask users questions as your code runs (like a message box with a text entry cell it the form).

It then goes on to show you how to use the IF statement which is probably the function you will use the most within your routine. However there are some times when there are too many options to write everything in IF statements and this is when you will need to use a SELECT CASE statement.

The SELECT CASE statement is covered at the 9 minute mark – so if you already know about the IF statement you can simply jump to the SELECT CASE part of the video.

If you have found this video useful please like or share the video using the buttons above, or leave us a comment below.


Tim says:

How do you add descriptions to a VBA function or Sub?
Specifically, when you hit fx on the cell using the function or sub, a dialog box pops up, but there is no description available.
Thanks for your videos they are very helpful
Tim McHale

Roger says:

Good question. And one I had to search the web for and answer. Here is an extract from http://spreadsheetpage.com/index.php/tip/user-defined_function_argument_descriptions_in_excel_2010/

Here’s a VBA macro that provides a description for the EXTRACTELEMENT function, assigns it to a function category, and provides a description for each of its three arguments:

Sub DescribeFunction()
Dim FuncName As String
Dim FuncDesc As String
Dim Category As String
Dim ArgDesc(1 To 3) As String

FuncDesc = “Returns the nth element of a string that uses a separator character”
Category = 7 ‘Text category
ArgDesc(1) = “String that contains the elements”
ArgDesc(2) = “Element number to return”
ArgDesc(3) = “Single-character element separator”

Application.MacroOptions _
Macro:=FuncName, _
Description:=FuncDesc, _
Category:=Category, _
End Sub

Write a comment


Skip Ad
Skip Panel
Skip Survey
It would be awesome to hit "like" or "share" and start playing.