IF is one of the most popular and frequently used statements in VBA. The task of the IF Statement is to check if a particular condition is met or not. If you have followed my earlier posts, then you would remember that we discussed If Function in Excel. Excel IF function checks a particular condition and if the condition is TRUE, it returns one value otherwise it returns the second value. If the condition evaluates to TRUE then, it simply takes the program control to the instructions inside the IF block and starts executing them sequentially.
VBA IF Statement – Explained With Examples
VBA Factorial Function | SuperExcelVBA
You can read it from start to finish as it is laid out in a logical order. If you prefer you can use the table of contents below to go to a section of your choice. Topics covered include Offset property , reading values between cells , reading values to arrays and formatting cells. If you are a member of the VBA Vault , then click on the image below to access the webinar and the associated source code. Note: Website members have access to the full webinar archive. This is the third post dealing with the three main elements of VBA.
Write Data to Text File
Declares the name, arguments , and code that form the body of a Function procedure. If not explicitly specified by using Public , Private , or Friend , Function procedures are public by default. If Static isn't used, the value of local variables is not preserved between calls. The Friend keyword can only be used in class modules. However, Friend procedures can be accessed by procedures in any module of a project.
The difference between a function and a sub in Excel VBA is that a function can return a value while a sub cannot. Functions and subs become very useful as program size increases. If you want Excel VBA to perform a task that returns a result, you can use a function. For example, the function with name Area. Explanation: This function has two arguments of type Double and a return type the part after As also of type Double.