Australasian Journal of Herpetology 22 Tidying up Death Adder ...
Excel: Tidying up Text (PC) - University of Brighton › is › Published Documents... · Excel:...
Transcript of Excel: Tidying up Text (PC) - University of Brighton › is › Published Documents... · Excel:...
[Type here]
Excel: Tidying up Text
(PC)
HOW TO CLEAN UP TEXT IN A FLASH
This document looks at some of the tools available in Excel for
manipulating text.
It is suitable for anyone who uses Excel for databases such as
lists of contacts, students or delegates.
This workbook assumes a working knowledge of Excel. A basic
knowledge of using functions in Excel like SUM and COUNT
would be an advantage.
You can download the exercise files for this workbook from our
website
https://staff.brighton.ac.uk/is/training/Pages/Excel/text.aspx
This document can be used with Excel 2010, 2013 or 2016 on
a Windows PC.
Last updated
28 August 2018
University of Brighton Information Services
Page | 2 Last Updated 28th August 2018
Contents
Find and Replace to update multiple entries in one hit ..................................... 3
Autofill to copy a formula down a column ......................................................... 4
Splitting one column of text into two or more columns ...................................... 5
Flash Fill (Excel versions 2013 onwards) ......................................................... 8
Merging Columns into one (CONCATENATE) ................................................11
Paste Values to avoid errors when deleting columns ......................................13
Changing the case of text (PROPER, UPPER & LOWER) ..............................16
Using the LOWER function .............................................................................17
Copying part of a column of text ......................................................................19
LEFT function to extract text from the left of a cell ..............................................19
RIGHT function to extract text from the right of a cell ..........................................19
MID function to extract text from the middle of a cell ...........................................19
Removing spaces (TRIM function)................................................................22
Duplicate entries ...........................................................................................24
Conditional formatting to identify duplicates .............................................24
Remove Duplicates ..................................................................................25
Use a formula to identify duplicate entries ................................................27
Copy & Transpose a column to a row ...........................................................30
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 3
Find and Replace to update multiple entries in one
hit
If you need to replace all instances of a certain string of text with another, use find
and replace:
Click on Find and Select in the Editing group on the Home tab
Click on Replace
Type the text that you want to replace in the Find what box
Type the text that you want to replace it with in the Replace with box.
Click on Replace all.
Exercise A Using Find and Replace
Open up the exercise file Find_Replace.xlsx. This is a membership list.
For this exercise, imagine that we have changed the branding of our membership
types. We have renamed our Life membership to now be called Super. We want to
therefore replace any instances of the word Life with the word Super.
Select the column containing the membership types by clicking on the column
header for column F.
Click on Find and Select in the Editing group on the Home tab
Click on Replace
Type Life in the Find what box. This asks
Excel to find all instances of the word Life.
Type Super in the Replace with box. This
tells Excel you want to replace the word
Life with the word Super.
Click on Replace all.
Excel will tell you how many replacements it has made. Click OK to close the
message.
Click Close to close the Find and Replace window.
University of Brighton Information Services
Page | 4 Last Updated 28th August 2018
Autofill to copy a formula down a column
When you want a formula to appear in every cell within a column:
Build the formula in the first cell in the column
Use autofill to copy the formula down the column
We will use the autofill technique throughout this booklet.
To use autofill:
Select the cell(s) you want to copy. The fill handle will
appear at the bottom right of the selection.
Point at the fill handle until it becomes a cross.
Click and drag to copy the data OR Double-click to autofill all rows.
Click on to change the type of fill (series, copy, formula only etc.)
Double click on one of the newly-populated cells within the column to check
that the copied cell references are correct.
Exercise B Using Autofill
Open up the exercise file Autofill.xlsx and double click on cell I2.
Cell I2 contains a formula to calculate the monthly payment for that row, based on
the annual fee in column G. We are going to copy this formula down the row to
automatically calculate the monthly fee for each row using the same formula.
Press Esc on your keyboard to exit the function.
Select cell I2. The fill handle will appear at the bottom right of
the cell.
Point at the fill handle until it becomes a black cross.
Click and drag down column I to copy the data OR double-click to autofill all
rows in the column. Double-click only works if the column to the left has data in
every cell.
Double click on one of the newly populated cells to check the cell references
for that row. When you have finished checking, press Esc on your keyboard to
exit the function.
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 5
Splitting one column of text into two or more
columns
(Convert Text to Columns)
Text to Columns can be used where a common character (delimiter) separates two
or more sections of text within each cell in a column.
Common delimiters include a space, semi-colon (;) or comma (,).
Check that there are enough empty columns to the right of the column you are
going to split. You will need one column per section of text to be split, including
the original column itself. To insert an empty column if needed:
Right-click on the column letter of the column to the right of the column you
want to split
Click on Insert
Click on the column heading of the column you want to split
On the Data tab, click on Text to
columns
The Convert Text to Columns
wizard appears.
For sections of text separated by commas,
spaces, semi-colons or other characters, check
that the Delimited option is selected and
click Next
In the Delimiters section, choose what character
separates the two sections of text in your column.
For instance, in the example at the top of the page,
a space separates the first name and the surname
in column B. So a space is the delimiter.
University of Brighton Information Services
Page | 6 Last Updated 28th August 2018
If the character separating your text is not in the list, choose Other
and then type the character used as the delimiter in the box as
shown on the right.
Click Next.
In the Data preview at the bottom of the window,
check that the proposed split is what you are
expecting and then click on Finish.
Exercise C Using Text to Columns
Open up the exercise file Text_to_Columns.xlsx. In this exercise we are
going to split the Name column into separate First Name and Surname
columns.
Our Name column has 2 words in each cell, separated by a space. So:
We need 2 columns for the split (including column B itself)
The delimiter (which tells Excel where to make the split) is a space.
Insert a blank column to the right of column B.
Select column B by clicking on the column letter.
On the Data tab, click on Text to columns
The Convert Text to Columns wizard appears.
Our text has a delimiter, so we do not change anything in the first step of the wizard, we simply click Next.
In the next step of the wizard, we must tell Excel
what the delimiter is. The default is a Tab. Our
delimiter is a space, so deselect Tab and click to
select Space.
Click Next.
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 7
In the Data preview at the bottom of the window, check that the proposed split is OK: check that each name has been split as you
were expecting.
Click on Finish.
University of Brighton Information Services
Page | 8 Last Updated 28th August 2018
Flash Fill (Excel versions 2013 onwards)
Flash Fill is a fantastic function that eliminates the need for some of the functions
mentioned later in this document. Using Flash Fill, you tell Excel what you would
like your text to look like and it tries to establish a rule that it can then apply to the
rest of the column. Flash Fill is not available in Excel 2010.
For a demo of how Flash Fill can save you hour of time, see the videos on our
website: https://staff.brighton.ac.uk/is/training/Pages/Excel/text.aspx
Using Flash Fill you can easily:
Merge content of several columns into one (replaces CONCATENATE in
earlier versions of Excel)
Correct the case of text within a column (replaces UPPER, LOWER and
PROPER functions in earlier versions of Excel)
Extract certain characters from a string within a column (replaces
LEFT, RIGHT, MID functions in earlier versions of Excel)
Exercise D Using Flash Fill
Open up the exercise file Flash Fill.xlsx.
First, we will use Flash Fill to create one new column containing both name and
surname for everyone in our list.
Click on cell D2, type ROGER WILSON and press ENTER.
Click back on cell D2 and use autofill to copy the content down column D.
Click on the icon at the bottom of the list and choose Flash Fill from the list
of options.
Column D has been populated with the full names of everyone, taking the case of
the text as it appears in columns B and C.
Next we will correct the case of the text.
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 9
Click back on cell D2, this time type Roger Wilson and press ENTER.
Click back on cell D2 and use autofill to copy the content down column D.
Click on the icon at the bottom of the list and choose Flash Fill from the list
of options.
Column D has been populated with the full names of everyone, but this time the
case has been taken from what we typed in cell D2.
Let’s correct the case of some other text. Let’s clean up the post code and the email
address columns.
Click on cell J2, type BN1 6HJ and press ENTER.
Click back on cell J2 and use autofill to copy the content down column J.
Click on the icon at the bottom of the list and choose Flash Fill from the list
of options.
Column J has been populated with the post codes in the correct format.
Click on cell I2, type [email protected] and press ENTER.
Use the arrow keys on your keyboard to move back to cell I2 and use autofill to
copy the content down column I.
Click on the icon at the bottom of the list and choose Flash Fill from the list
of options.
Column I has been populated with the email addresses in the correct format.
Now delete columns H and I as they are no longer needed.
Now let’s look at pulling part of a string of text:
Click on the LEFT_RIGHT_MID tab.
We will spilt the EFIN codes in column B into their component parts (Account = first
4 characters, Activity = next 4 characters, Job Code = next 5 characters)
Click in cell C2 and type J20U.
Click back on cell C2 and use autofill to copy the content down column C.
Click on the icon at the bottom of the list and choose Flash Fill from the list
of options.
Click in cell D2 and type 1900.
Click back on cell D2 and use autofill to copy the content down column D.
University of Brighton Information Services
Page | 10 Last Updated 28th August 2018
Click on the icon at the bottom of the list and choose Flash Fill from the list
of options.
Click in cell E2 and type G1000.
Click back on cell E2 and use autofill to copy the content down column E.
Click on the icon at the bottom of the list and choose Flash Fill from the list
of options.
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 11
Merging Columns into one (CONCATENATE)
NOTE THAT IN EXCEL 2013 AND 2016 FLASH FILL CAN BE USED INSTEAD OF THIS.
This involves three steps:
Insert a new column
In the new column, use the CONCATENATE function to build the new string of
text
Use Paste Values to strip the CONCATENATE formula from the new column,
leaving just the string of text (only needed if you want to delete the original
columns)
Format Example Result
=CONCATENATE(text1, text2,…)
Where text can be:
A cell reference
Fixed text (always contained
within quotation marks “”)
=CONCATENATE(B2,“ ”,C2) Roger Wilson
=CONCATENATE(“Patient’s name is”,B2,“
”,C2) Patient’s name is
Roger Wilson
Exercise E Using CONCATENATE
Open up the exercise file CONCATENATE_1.xlsx. In this exercise we are
going to merge the Name and Surname columns into one column.
Insert a new column to the right of column C and type Full Name as the
column heading.
In cell D2, start your CONCATENATE function by typing =CONCATENATE(
Use your mouse to click on cell B2 and then type a comma (to say you have
finished identifying the first part of the text string). Your function will now read
=CONCATENATE(B2,
We want a space to appear between the first name and surname. To achieve
this, type “ “, Your function will now read =CONCATENATE(B2,” “, with the final
comma indicating that you have finished identifying the second part of the text
string
University of Brighton Information Services
Page | 12 Last Updated 28th August 2018
Use your mouse to click on cell C2. Your function will now read
=CONCATENATE(B2,” “,C2
Press ENTER on your keyboard to complete the function and copy the formula
down the column using autofill.
To enable us to delete columns B and C we will now need to Paste Values, as
explained in the next section
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 13
Paste Values to avoid errors when deleting
columns
NOTE THAT IN EXCEL 2013 AND 2016 FLASH FILL CAN BE USED INSTEAD OF THIS
After using a text function like CONCATENATE, we often want to delete the
columns referenced in the function, leaving just the new column containing the
result of the function. For example, in the exercise on the previous page, we may
want to delete column B (First Name) and column C (Last Name) and just leave the
new column D (Full Name).
If a text function like CONCATENATE, PROPER or LEFT references cells in other
columns, simply deleting those columns will result in an error as the text function
will no longer be able to find the cells it references.
Before we can delete the referenced columns, we must first remove any functions
that reference the columns you want to delete. To do this:
Select the column containing the text function (e.g. the
CONCATENATE function) by clicking once on the column
header
On the Home tab, click on to copy the selected
column
On the Home tab, click on the drop-down arrow below the
Paste icon
Click on Paste Values icon
This copies and pastes the column over itself. Using Paste Values pastes in just
the values (the result of the function) rather than the function itself. This removes
any references to other columns and enables you to delete the unwanted
referenced columns without any problem.
PASTE
VALUES
University of Brighton Information Services
Page | 14 Last Updated 28th August 2018
Exercise F Demonstration of what happens if we do not use Paste Values
Let’s see what happens if we just try to delete the referenced columns without using
Paste Values first of all:
Use the file from the previous exercise or open the file
CONCATENATE_2.xlsx
Double-click on cell D2 to remind yourself of its contents. The cells referenced
in columns B and C are highlighted. Press Esc on your keyboard to exit the
function.
Delete column B. Column D shows #REF! to indicate that there is a problem
with the formula contained in that column. This is because column B was
referenced by the CONCATENATE function used in that column.
Click on Undo to back out the deletion of column B.
So simply deleting referenced columns will not work. Next, let’s see what happens if
we use a simple Copy and Paste:
Double click on cell D2 to remind yourself of its contents (a CONCATENATE
function) and then press Esc on your keyboard to exit the function.
Select column D by clicking on the column header.
On the Home tab, click on to copy the selected column
On the Home tab, click on Paste to paste replace column D with the copied
cells.
Double click on cell D2 to check its contents now. It still contains the
CONCATENATE function and the cell references. Nothing has changed. If we
delete columns B and C now we will have the same problem as before.
Press Esc on your keyboard to exit the function.
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 15
Exercise G Using Paste Values
Here’s how to do it properly:
Select column D by clicking on the column header.
On the Home tab, click on to copy the selected
column
On the Home tab, click on the drop-down arrow below the
Paste icon
Click on Paste Values
Double click on cell D2 to check its contents now. It now contains only text –
the names themselves. Paste Values has pasted the result of the
CONCATENATE function into column D, rather than the function itself.
Delete columns B and C. As column D no longer contains the CONCATENATE
function, it no longer references columns B and C and you are able to delete
them without any problem.
We will use this technique of copying a column and pasting its values back upon
itself over and over when using text functions.
University of Brighton Information Services
Page | 16 Last Updated 28th August 2018
Changing the case of text (PROPER, UPPER &
LOWER)
NOTE THAT IN EXCEL 2013 AND 2016 FLASH FILL SHOULD BE USED INSTEAD OF THIS.
Sometimes the text in a column of text is not consistent. For instance, if an address
database has been built by people submitting a form online, some names will be
UPPER CASE, whilst others will be lower case whilst others may be a mixture of
the two. If we want to use those names for professional-looking mail-merges, we
first need to clean up the text so that it is consistent.
There are a number of text functions available for changing the case of text:
Format Example Result Notes
=PROPER(text)
Where text can be a
cell reference
=PROPER(B2) ROGER WILSON becomes Roger
Wilson
roger wilson becomes Roger Wilson
Roger Wilson will stay as Roger Wilson
Useful for
lists of
names
=UPPER(text)
Where text can be a
cell reference
=UPPER(B2) ROGER WILSON will stay as ROGER
WILSON
roger wilson becomes ROGER WILSON
Roger Wilson becomes ROGER
WILSON
Useful for
post codes
in address
lists
=LOWER (text)
Where text can be a
cell reference
=LOWER(B2) ROGER WILSON becomes roger wilson
roger wilson will stay as roger wilson
Roger Wilson becomes roger wilson
Useful for
addresses
The technique for using any of these text functions is the same:
Insert a new column
In the new column, use the relevant text function to convert the text from
another column
Use Paste Values to strip the text function from the new column, leaving just
the text itself
Delete the original columns if needed
The exercises on the next page walk you through each function.
Exercise H Using the PROPER function
This function is useful for lists of names. The first letter of each word is converted to
upper case and all other letters are converted to lower case.
Open the exercise file Case_Functions_1.xlsx
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 17
In this exercise we are going to use the PROPER function to convert the name and surnames in the list.
Insert 2 new columns to the right of column C. This should create columns D
and E as empty columns.
In cell D2, start your PROPER function by typing =PROPER(
Use your mouse to click on cell B2 (the first name). The function will now read
=PROPER(B2
Press ENTER on your keyboard to complete the function and then copy the
formula down the column using autofill.
Repeat steps 3-5, but this time convert the surnames in column C so that they
appear in column E.
Follow the Paste Values technique to delete columns B and C without losing
the text in columns D and E (see page 8)
Exercise I Using the UPPER function
This function is useful for post codes in address lists. All letters are converted to
UPPER CASE.
Continue with the exercise file Case_Functions_1.xlsx In this exercise we are going to use the UPPER function to convert the post codes in the list.
Insert a new column to the right of the Post Code column. This should create
column H as an empty column.
In cell H2, start your UPPER function by typing =UPPER(
Use your mouse to click on cell G2 (the first post code). The function will now
read =UPPER(G2
Press ENTER on your keyboard to complete the function and then copy the
formula down column H using autofill.
Follow the Paste Values technique to delete column G without losing the text
in columns H (see page 8)
Using the LOWER function
This function is useful for email addresses in contacts lists. All letters are converted
to lower case.
University of Brighton Information Services
Page | 18 Last Updated 28th August 2018
Continue with the exercise file Case_Functions_1.xlsx In this exercise we are going to use the LOWER function to convert the email addresses in the list.
In cell I2, start your LOWER function by typing =LOWER(
Use your mouse to click on cell H2 (the first email address). The function will
now read =LOWER(H2
Press ENTER on your keyboard to complete the function and then copy the
formula down column I using autofill.
Follow the Paste Values technique to delete column H without losing the text
in columns I (see page 8)
HANDY HINT: If you want to change the case of text in Microsoft Word or Outlook:
Select the text you want to change
Press the SHIFT and F3 keys together:
pressing once will convert all text to UPPER CASE
pressing once again will convert all text to lower case
pressing once again will convert all text to Proper case
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 19
Copying part of a column of text
NOTE THAT IN EXCEL 2013 AND 2016 FLASH FILL SHOULD BE USED INSTEAD OF THIS.
Sometimes multiple strings of text appear together in one column when you would
prefer them to be in separate columns, but there is no delimiter between the strings
of text to enable us to use Text to Columns. This can happen with codes and data
extracted from other systems.
There are a number of text functions available for extracting characters from a
string of text:
LEFT function to extract text from the left of a cell
The format of the function is: =LEFT(text,number_of_characters) where:
text is a cell reference
number_of_characters is the number of characters you want to copy
In cell C2 in the example above, the formula would be =LEFT(B2,4)
RIGHT function to extract text from the right of a cell
The format of the function is: =RIGHT(text,number_of_characters) where:
text is a cell reference
number_of_characters is the number of characters you want to copy
In cell E2 in the example above, the formula would be =RIGHT(B2,5)
MID function to extract text from the middle of a cell
The format of the function is: =MID(text,start_number,number_of_characters)
where:
text is a cell reference
University of Brighton Information Services
Page | 20 Last Updated 28th August 2018
start_number is where you want to start from (counting the number of
characters from the left of the cell)
number_of_characters is the number of characters you want to copy
In cell D2 in the example above, the formula would be =MID(B2,5,4)
We’re going to replicate the example above, splitting the EFIN code into its
component parts.
Exercise J Using the LEFT function
Open the exercise file LEFT_RIGHT_MID.xlsx
In cell C2, start your LEFT function by typing =LEFT(
Click on cell B2 and then type a comma to tell Excel that you have finished that
piece of information. Your function should now read =LEFT(B2,
Type 4 to indicate that you want to extract the first 4 characters of the text in
cell B2. Your function should now read =LEFT(B2,4
Press ENTER on your keyboard to complete the function and then copy the
formula down the column using autofill.
Exercise K Using the RIGHT function
In cell E2, start your RIGHT function by typing =RIGHT(
Click on cell B2 and then type a comma to tell Excel that you have finished that
piece of information. Your function should now read =RIGHT(B2,
Type 5 to indicate that you want to extract the last 5 characters of the text in
cell B2. Your function should now read =RIGHT(B2,5
Press ENTER on your keyboard to complete the function and then copy the
formula down the column using autofill.
Exercise L Using the MID function
In cell D2, start your MID function by typing =MID(
Click on cell B2 and then type a comma to tell Excel that you have finished that
piece of information. Your function should now read =MID(B2,
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 21
Type 5 to indicate that you want start extracting characters from the fifth
character, counting from the left of cell B2. Your function should now read
=MID(B2,5
Type a comma to tell Excel that you have finished that piece of information.
Your function should now read =MID(B2,5,
Type 4 to indicate that you want to extract 4 characters of the text (starting
from the character identified in step 3). Your function should now read
=MID(B2,5,4
Press ENTER on your keyboard to complete the function and then copy the
formula down the column using autofill
University of Brighton Information Services
Page | 22 Last Updated 28th August 2018
Removing spaces (TRIM function)
Sometimes erroneous spaces within a cell will affect how well functions such as
LEFT, MID and RIGHT perform (see cell E4 in the previous exercise – a space at
the end of the text in cell B4 results in the first character being omitted, resulting in
1000 instead of the expected G1000). As these spaces are usually quite difficult to
find, it is useful to perform a blanket clean-up of a column before using other text
functions on that column. To do this we use the TRIM function.
The technique for the TRIM functions is the same as for other text functions such as
PROPER:
Insert a new column
In the new column, use the TRIM function to convert the text from another
column
Use Paste Values to strip the text function from the new column, leaving just
the text itself. If you already have functions dependent on the original column,
you may need to copy the new column but paste it over the original column to
avoid errors with dependent cells – see the technique used in the exercise
below.
Delete the extra column if needed
The format of the function is: =TRIM(text) where text is a cell reference.
In cell C2 in the example above, the formula would be =TRIM(B2). Let’s practise
that.
Exercise M Using the TRIM function
Continue with the exercise file LEFT_RIGHT_MID.xlsx
Insert a new column to the right of column B.
In cell C2, start your TRIM function by typing =TRIM( and then click on cell
B2. Your function should now read =TRIM(B2
Press ENTER on your keyboard to complete the function and then copy the
formula down the column using autofill.
Select column C by clicking on the column header.
On the Home tab, click on to copy the selected
column
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 23
Select column B by clicking on the column header.
On the Home tab, click on the drop-down arrow below the
Paste icon and then click on Paste Values ( icon in
Excel 2010)
Delete column C.
University of Brighton Information Services
Page | 24 Last Updated 28th August 2018
Duplicate entries
There are a number of ways of handling duplicate entries in your data. We’ll look at
just some here.
Conditional formatting – this will colour duplicate entries within a column. The
technique shown here can only be used to find duplicates within one column
and not to find duplicates by comparing multiple columns in rows.
Remove duplicates – this finds duplicates and deletes them. Only to be used
when you are confident that you are happy to delete duplicates without
checking them first.
Use a formula to identify duplicates – This allows you identify duplicates by
checking multiple columns. Useful if you want to check duplicates before
deleting them. Each of these options is explained below.
Conditional formatting to identify duplicates This will colour duplicate entries within a column. The technique shown here can
only be used to find duplicates within one column and not
to find duplicates by comparing multiple columns in rows.
Click on the column you want to analyse
On the Home tab, click on the Conditional
Formatting icon
Click on Highlight Cell Rules
Click on Duplicate Values
A pop-up window appears. Choose how you
want to format the duplicates and click OK.
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 25
Exercise N Using conditional formatting to identify duplicates
Open the exercise file Duplicates.xlsx
On the Conditional Formatting tab, select column A by
clicking on the column header.
On the Home tab, click on the Conditional Formatting icon
and then click on Highlight Cell Rules.
Click on Duplicate Values.
Choose to format duplicate entries with Red Text and then click OK. All
duplicate entries in column A will be coloured red.
Remove Duplicates This is the fastest way of eliminating duplicates from your data. You tell Excel how
to identify the duplicates and it finds them and deletes them for you.
The deletion happens immediately. There is no option to check the duplicates. If
you want to check the duplicates first, do not use this option.
To remove duplicates:
Click anywhere in your data
On the Data tab, click on Remove
Duplicates
In the pop up window, specify which columns
to use for checking for duplicate entries.
Click OK.
University of Brighton Information Services
Page | 26 Last Updated 28th August 2018
Exercise O Using Remove Duplicates
Continue with the exercise file Duplicates.xlsx. Click on the Remove
Duplicates worksheet. Take a look at the data and see which rows are similar
to others.
First let’s see what happens if we only duplicate rows with a match in every column.
Click once anywhere in the list and then click on Remove Duplicates on the
Data tab.
In the pop up window, leave all of the columns selected and click OK.
Excel will find no duplicates. This is because it is checking every column for
duplicates and column D has unique values.
Now let’s change the criteria to exclude column D from the check.
On the Data tab, click on Remove Duplicates
In the pop up window, deselect the Hours
worked column and click OK.
Excel will remove 2 duplicate rows – compare
your results with the original list shown above
(or on the Conditional Formatting worksheet) to see what has been deleted.
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 27
Use a formula to identify duplicate entries This technique involves using a formula to make an entry in a separate column to
indicate if a row is a duplicate. You can then sort the spreadsheet and check the
duplicate rows to decide what to do with them.
In the example on the left
we have determined a
duplicate to be those rows
where columns A, B and C
match columns A, B and C
in another row.
This technique uses the COUNTIFS function, which counts cells that meet certain
criteria.
Format Example
=COUNTIFS(range of cells for criteria
check 1, criteria 1 to satisfy, range of cells
for criteria check 2, criteria 2 to satisfy,...)
=COUNTIFS(A1:A10,”Gold”,B1:B10,”>20”)
Counts number of rows where column A
contains the word Gold AND column B is
greater than 20
To use COUNTIFS to find duplicates, the format of the function is:
=COUNTIFS(A:A,An,B:B,Bn,...) where:
n is the current row number
A, B etc. are the columns to check for a match So, in our example above, the function in cell E2 would read:
=COUNTIFS(A:A,A2,B:B,B2,C:C,C2)
i.e. How many times does the content of A2 appear anywhere else in column A
(A:A) at the same time as the content of B2 appears somewhere else in column B
(B:B) and the content of C2 appears somewhere else above in column C (C:C)?
Any result greater than 1 indicates that a duplicate has been found for that
row.
The count will always be at least 1 as the cell being checked for (e.g. A2) always
appears once in the column (e.g. column A).
Exercise P Using COUNTIFS to identify duplicate rows
Let’s practise using our spreadsheet.
Open the exercise file Duplicates.xlsx. Click on the Unique Entries Formula
worksheet.
We are going to check for rows that have the same Payroll number and Name. We
will use column E for this.
Click on cell E2 and type =COUNTIFS( to start the function
In this row (row 2) we are going to check:
University of Brighton Information Services
Page | 28 Last Updated 28th August 2018
If cell A2 matches any cells in column A
If cell B2 matches any cells in column B
Click on the letter A at the top of column A to select that column. This asks
Excel to check column A. The function in cell E2 will read: =COUNTIFS(A:A
Type a comma to indicate that you have finished this piece of information.
Click on cell A2. This asks Excel to look for a match for the contents of cell A2.
The function in cell E2 will read: =COUNTIFS(A:A,A2
Type a comma to indicate that you have finished this piece of information.
Repeat steps 3-5 for column B to ask Excel to check if the contents of cell B2
appear anywhere else in column B (you do not need a comma at the end of the
function). The function in cell E2 will read: =COUNTIFS(A:A,A2,B:B,B2
Press ENTER to complete the condition. The function in cell E2 will be
=COUNTIFS(A:A,A2,B:B,B2) The result will be 3. This row appears 3 times.
Copy the formula down column E using autofill.
Take a look at the results in column E. Based on our criteria (a match in both
columns A and B) only 2 rows are unique. These are identified with a 1 in
column E.
You can include as many columns as you need in your check. Let’s add column C
to our check.
Double click on cell E2 to edit the formula.
Click just after the B2 reference so that your insertion point is flashing in
between the 2 and the final bracket.
Type a comma to indicate that you are going to add another condition to the
function.
Follow steps 3-5 for column C to ask Excel to check if the contents of cell C2
appear anywhere else in column C. The function in cell E2 will be read
=COUNTIFS(A:A,A2,B:B,B2,C:C:C2)
Press ENTER to complete the condition and copy the formula down column E
using autofill.
If you would prefer your duplicates to be identified using text rather than numbers:
Add >1 to the end of your function. So in cell E2 in the exercice above, the
function would read =COUNTIFS(A:A,A2,B:B,B2,C:C:C2)>1
Excel: Tidying up Text (PC)
Printed Tuesday, 28 August 2018 Page | 29
Copy the function down the cells using Autofill. The example below shows how this would appear in the spreadsheet:
Where the count is greater than 1 (duplicates), the result of the function will be
TRUE.
Where the count = 1 (no duplicate), the result of the function will be FALSE.
Note: A green triangle may appear in the cells in column E when using this
formula. This is because the formula checks all cells in the column. As some of the
cells are empty, Excel gives you a warning to tell you that you have referenced
empty cells in your formula. This is not a problem here and you can
ignore this in this instance.
If you see a green triangle in a cell in Excel you should always check it by:
Clicking once in the cell showing the green triangle
Clicking on the icon that appears to the left.
University of Brighton Information Services
Page | 30 Last Updated 28th August 2018
Copy & Transpose a column to a row
You can turn a column of text into a row of text and vice-versa. You do this by
copying the text and choosing Transpose instead of Paste to paste the text.
This is not used often, but it can really save you time when you need it.
select the text you want to move
On the Home tab, click on to copy the selected cells
Click where you want to paste the copied cells
On the Home tab, click on the drop-down arrow below the Paste
icon
Click on Transpose
Exercise Q Using Copy & Transpose
Let’s practise that technique.
Open the exercise file Paste_Transpose.xlsx
Select cells A2 to A13.
On the Home tab, click on to copy the selected cells
Click in cell B1.
On the Home tab, click on the drop-down arrow below the Paste
icon
Click on Transpose
COPY &
TRANSPOS
E