0% found this document useful (0 votes)
10 views7 pages

S6 Collections With IF Start

This document provides an overview of various looping and conditional coding techniques in Excel VBA including: 1) Using With...End With blocks to simplify code writing and maintenance when formatting ranges. 2) Looping through collections like sheets and ranges to perform actions on multiple objects at once. 3) Using IF...Then and IF...ElseIf...Else statements to add conditional logic and outcomes. 4) The Select Case statement as an alternative to complex IF structures. 5) The Goto statement to change program flow, useful for error handling. 6) An activity to get the number of formulas on a worksheet using a macro.

Uploaded by

roll_witit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

S6 Collections With IF Start

This document provides an overview of various looping and conditional coding techniques in Excel VBA including: 1) Using With...End With blocks to simplify code writing and maintenance when formatting ranges. 2) Looping through collections like sheets and ranges to perform actions on multiple objects at once. 3) Using IF...Then and IF...ElseIf...Else statements to add conditional logic and outcomes. 4) The Select Case statement as an alternative to complex IF structures. 5) The Goto statement to change program flow, useful for error handling. 6) An activity to get the number of formulas on a worksheet using a macro.

Uploaded by

roll_witit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 7

What you learn Looping through Collections & Conditional Outcomes

Link Topic Covered What you Learn

With With…End With for Easier Methods to simplify writing & maintenance of code
Code Writing
Collections Looping Through Collections • How to efficiently loop through members of a
(Sheets, Ranges etc.) in One collection in one go.
Go • For example loop through many worksheets, cells
etc.
• Protect & Unprotect all sheets in one go

IF Conditional Outcomes with • Add conditions & decide the outcome


IF…Then Statements • Simple IF…Then
• IF…ElseIF…Else statement
• IF…Else statement

Case Select Case, as Alternative Select Case statement as an alternative to a complex


for Many IFs IF statement
GoTo Goto Statement to Change How to change the flow of code. This is specially
Program Flow useful for error handling
Activity Activity: Get the Number of For the used range on the sheet, get the number of
Formulas on the Worksheet cells that have formulas in them
With…End With for Easier Code Writing

For the range below make the following changes:


• font = Arial
• font size 12
• font is bold

WenCaL
Blend
Voltage
Twistrr
Inkly
Sleops
Misty Wash
Kind Ape
Pet Feed
Right App
Mirrrr
Halotot
Flowrrr
Silvrr
Commuta
Rehire
Looping Through Collections (Sheets, Ranges etc.) in One Go
2 examples of using collections

Task 1: Protect all sheets in this workbook


…allow formatting though

Task 2: Unprotect all sheets in this workbook


Conditional Outcomes with IF…Then Statements

Copy only if cell has text or number (not if it's blank) 5

Copy B4 to C4 only if the number is between 0-400 300

Protect Specific Sheets

Protect all sheets but allow formatting except for:


1. Sheet "Purpose" - this should be protected but no formatting should be allowed
2. Sheet "With" should not be protected
Select Case as Alternative for Many IFs

Input a number in cell B3 to get


status in C3 400

Status as follows:
1. cell value is between 1 to 200 --> Good
2. cell value Is 0 status should be empty
3. cell value is greater than 200 --> Excellent
4. cell value is less than 0 --> Bad
Goto Statement to Change Program Flow

Copy B3 to C3 only if
B3 has a value #DIV/0!
Activity: Get the Number of Formulas on the Worksheet

For the used range on this sheet, use a macro to get the number of cells that have formulas in them
Place this value inside cell B6. Create a button and assign the macro to it.

How many formula cells are on this sheet? 2

Calculation mode: Automatic


Date: 11/15/2023

You might also like