This document provides an agenda for a workshop on using Excel for insights. The agenda covers Excel basics like formulas, functions and editing. It also covers topics specific to analyzing survey data like recoding data using IF statements, describing data using functions, summarizing data with pivot tables, visualizing data through charts, linking data and charts, and automating tasks through macros and VBA. The document includes 3 sections on removing NA and blank values from a dataset using VBA code.
3. Agenda
• Excel basics
• Survey data basics
• Pivot tables and survey data
• Visualization
• Automation
• Q&A
Using Videos
4. Basics - 1
• Introducing some data
• Formulas
• Functions
• Editing Using a PC?
I am on a Mac – when I press the
Command key, PC users will typically
press the Ctrl key.
24. Remove NA & None 1 of 3
Option Explicit ' this requires all variables to be declared
'Routine to tidy out NA from a list
'Author Ray Poynter
Sub RemoveNA()
'Declare the variables
Dim lRow As Long 'how many rows
Dim iNA As Integer 'the number strings to mark as NA
Dim sNA() As String 'An array holding all the versions of NA we are going to check for
Dim i As Integer, j As Integer 'counters
Dim sVerbatim As String ‘the verbatim we are processing at the moment
Dim iVerbatim As Integer 'which column has the verbatims in
Dim iOutput As Integer 'which column to write the cleaned verbatims
Dim bFlag As Boolean 'is a verbatim a NA?
25. Remove NA & None 2 of 3
Sheets("Automate 2").Select 'make the test sheet the selected one
'Define the NA codes
iNA = 2 'in this example we have just verbatims that are NA, but it could be a list of 10, 20 or more alternatives
ReDim sNA(iNA)
sNA(1) = "NA"
sNA(2) = "NONE"
'Define the input and output columns
iVerbatim = 8
iOutput = 9
'Find out how many rows of data there are
lRow = ActiveSheet.UsedRange.Rows.Count
'Create the heading
Cells(1, iOutput) = "Favourite Bank - Cleaned"
26. Remove NA & None 3 of 3
'Work through the rows
For i = 2 To lRow 'we start at 2, because 1 is the heading
sVerbatim = Cells(i, iVerbatim) 'read the verbatim
sVerbatim = Trim(sVerbatim) 'remove any preceding or trailing spaces
sVerbatim = UCase(sVerbatim) 'convert the verbatim to upper case
bFlag = False 'initially set the flag to not an NA
For j = 1 To iNA 'check the verbatim against each of the items in our list
If sVerbatim = sNA(j) Then bFlag = True 'If the verbatim is an NA set the flag
Next j
If bFlag = True Then
Cells(i, iOutput) = "" 'If an NA, write a blank
Else
Cells(i, iOutput) = Cells(i, iVerbatim) 'If not an NA, write the verbatim out
End If
Next i
End Sub