19 Practical Data Cleaning Techniques in Excel

 

Method 1 – Remove Duplicate Rows

Here’s a sample dataset that contains duplicate rows.

removing duplicate rows for data cleaning techniques in excel

Let’s replicate the column and remove the duplicates to compare them later on.

copied columns with duplicate rows in data cleaning techniques in excel

Steps:

  • Select the column you want to remove the duplicates from.
  • Go to the Data tab on your ribbon.
  • Select Remove Duplicates from the Data Tools group.

selecting remove duplicate feature

  • Select the Continue with the current selection option in the pop-up box and click on Remove Duplicates.

  • Click on OK.

keeping unique data in data cleaning techniques in excel

  • This will remove all the duplicates from the selection.

data cleaning techniques in excel: removed duplicate rows

Read More: How to Clean Survey Data in Excel


Method 2 – Highlight Duplicate Values

Utilizing Conditional Formatting

We’ll use the following dataset.

Steps:

  • Select the cells that we want to highlight. In this case, it is D5:D18.
  • Go to Home and choose Conditional Formatting.
  • Go to Highlight Cells Rules and select Duplicate Values.

highlighting duplicate value option in data cleaning techniques in excel

  • A Duplicate Values window will appear.
  • Choose Duplicate.
  • Select any color options after values with. We have selected Light Red Fill with Dark Red Text.

formatting duplicate values with condition

  • The duplicate values in the D column are highlighted.

duplicate values highlighted with conditional formatting in data cleaning techniques in excel

Highlighting Duplicates Including First Occurrence

Steps:

  • Go to the New Formatting Rule window in Conditional Formatting

new rule for highlighting duplicate values in data cleaning techniques in excel

  • Choose Use a formula to determine which cells to format.
  • Use the following formula in the formula box.

=COUNTIF($D$5:$E$16,$D5)>1

  • The D column is highlighted for duplicates, including the first occurrences.

duplicate values highlighted

Highlighting Duplicates Excluding First Occurrence

Steps:

  • Go to New Formatting Rule through the Conditional Formatting option.

  • Select Use a formula to determine which cells to format.
  • Use the following formula in the formula box.

=COUNTIF($D$5:$D5,$D5)>1

  • Click OK for the result.

highlighting duplicates excluding first occurrence in data cleaning techniques in excel

Read More: How to Clean Up Raw Data in Excel


Method 3 – Split Text into Multiple Cells

Here’s a dataset where each cell has multiple values that need to be split.

merged data in data cleaning techniques in excel

Steps:

  • Select the range you want to split text from.
  • Go to the Data tab on your ribbon.
  • From the Data Tools group, select Text to Columns.

text to column option for splitting cells in data cleaning techniques in excel

  • Select Delimited in the next box.

delimited option for splitting cell values in data cleaning techniques in excel

  • After clicking on Next, another box will appear.
  • Select Space under Delimiter options as the text is divided by spaces.
  • Click on Next.

correct delimiters

  • Click on Finish.

  • The text will be split.

  • Let’s make some modifications to make the data more presentable.

data split in data cleaning techniques in excel


Method 4 – Transforming Data with Formulas

The three formulas to change text are:

UPPER: This formula converts the text to ALL UPPERCASE.

LOWER: This formula converts the text to all lowercase.

PROPER: This one converts the text to Proper Case (the first letter in each word will be capitalized, as in a proper name).

We will use the following dataset.

changing case dataset for data cleaning techniques in excel

Changing to Upper Case

Steps:

  • Select cell C5.
  • Use the following formula in it.

=UPPER(B5)

upper formula for case change in data cleaning techniques in excel

  • Press Enter.

  • Select the cell again and click and drag the fill handle icon down to fill the rest of the cells with the formula.

upper formula result in data cleaning techniques in excel

Changing to Lower Case

Steps:

  • Select cell D5.
  • Use the following formula in it.

=LOWER(B5)

lower formula for case change in data cleaning techniques in excel

  • Press Enter.

  • Select the cell again and click and drag the fill handle icon down to fill the rest of the cells with the formula.

lower formula result data cleaning techniques in excel

Changing to Proper Case

Steps:

  • Select cell E5.
  • Use the following formula in it.

=PROPER(B5)

  • Press Enter.

  • Select the cell again and click and drag the fill handle icon down to fill out the rest of the cells.

proper formula result in data cleaning techniques in excel


Method 5 – Remove Extra Spaces

We have a dataset where the values have extra spaces between them.

Using the TRIM Function

The TRIM function removes all leading and trailing spaces from a text and replaces multiple spaces with a single space.

Steps:

  • Add a column D named Updated Data to show the results.
  • Click on cell D5.
  • Type =TRIM and select Cell C5 in the first argument. Close the parenthesis.
  • The formula becomes:

=TRIM(C5)

  • Press Enter.

removing extra space using trim function in data cleaning techniques in excel

  • Drag the Fill Handle icon down to the last cell.

space removed using trim function in data cleaning techniques in excel

Using the Find & Replace Feature:

Steps:

  • Select the data from where you want to remove the extra spaces.
  • Go to the Home tab.
  • From the Editing command, go to the Find & Select feature.
  • Select Replace from the drop-down list.

removing extra spaces in data cleaning techniques in excel using find & replace feature

  • You will get a dialog box.
  • Type a blank space in the Find what field.
  • Keep the Replace with box empty.
  • Click Replace All.

  • You’ll get a Pop-Up showing the number of replacements.
  • Click OK.
  • Click Close on the dialog box.
  • Here’s the result.

extra spaces removed using find & replace feature in data cleaning techniques in excel


Method 6 – Remove Strange Characters

You can use the CLEAN function to remove all non-printing characters from a text.

If the data is in cell A2, use this formula:

=CLEAN(A2)

The CLEAN function sometimes may miss some non-printing Unicode characters. It’s programmed to remove the first 32 non-printing characters in the 7-bit ASCII code. Browse the Excel Help system for information on how to remove the non-printing Unicode characters.


Method 7 – Convert Values

Let’s look at a dataset of temperatures that we need to convert between Celsius and Fahrenheit.

Steps:

  • Select the output cell D5.
  • Use the following formula:

=CONVERT(C5,"C","F")

  • Press Enter.

converting degree c to f in data cleaning techniques in excel

  • Click and drag the fill handle icon to the end of the column to convert all values.

Celsius to Fahrenheit converted in data cleaning techniques in excel

For other unit conversions, check out this article.


Method 8 – Highlight Errors

Suppose we have a dataset with some errors in some cells. We will highlight them with conditional formatting and the Go to Special feature.

Steps:

  • Select the whole dataset and click New Rule from the Conditional Formatting options.

setting new rule for highlighting error in data cleaning techniques in excel

  • Choose Format Only cells that contain and select Errors from the drop-down list.

highlighting error options in data cleaning techniques in excel

  • Click on OK.
  • Excel highlighted the error values.

errors highlighted in data cleaning techniques in excel


Method 9 – Join Columns

We’ll combine the first, middle, and last names in a single value for each entry in the list.

Steps:

  • Select cell E5.
  • Use the following formula.

=B5&" "&D5&" "&C5

  • Press Enter.

joining columns using ampersand

  • Click and drag the fill handle icon to the end of the column to replicate the formula for the rest of the cells.


Method 10 – Rearrange Columns

Here’s a sample dataset where we’ll rearrange some columns.

Steps:

  • Select the column you want to move by clicking on the column header.
  • Cut the column using either the context menu or pressing Ctrl + X. You will see a dotted line at the border of the selection.

cutting column for rearrange in data cleaning techniques in excel

  • Right-click on the column header before which you want to place the previous column.
  • Select Insert Cut Cells from the context menu.

insert cut cells option for rearranging columns in data cleaning techniques in excel

  • This will insert the previous column there.

columns rearranged in data cleaning techniques in excel


Method 11 – Randomize Rows

We’ll randomize the row order for the following dataset.

Steps:

  • Click the header letter of column C, and the whole C column will be selected.
  • Right-click and choose the Insert command, and a new column C will be created.

  • Assign a name to the newly created column (i.e. Random Number).
  • Select the first cell (i.e. C5) and insert the following formula into the cell.

=RAND()

  • Press Enter, and a random number will be displayed in cell C5. The number is lower than 1.

inserting random number for randomizing rows in data cleaning techniques in excel

  • Select the cell again and click and drag the fill handle icon to the end of the column to replicate the formula for the rest of the cells.

filling up with random numbers

  • With cell C5 selected, go to the Home tab.
  • Go to the Editing group and click Sort & Filter.
  • Select Sort Smallest to Largest from the drop-down menu.

sorting after inserting random number

  • The rows will randomize themselves. Excel will sort the dataset based on the values in column C, but the function in the column will then generate new values, so you can repeat the sort with different results.

randomized order of rows in data cleaning techniques in excel


Method 12 – Extract the File Name from an URL

Steps:

  • Cell B5 contains the URL of a file.
  • Select the cell where you want to put the file name. In this case, it is cell C5.
  • Use the following formula in it.

=RIGHT(B5,LEN(B5)-FIND("*",SUBSTITUTE(B5,"/","*",LEN(B5)-LEN(SUBSTITUTE(B5,"/","")))))

extracting file name from url formula in data cleaning techniques in excel

  • Press Enter.

file name from url excel

Breakdown of the Formula

SUBSTITUTE(B5,”/”,””) removes all the “/” from the URL. It returns http:www.example.comassetsimageshorse.jpg.

LEN(SUBSTITUTE(B5,”/”,””)) returns the length of the previous string.

LEN(B5) returns the length of the string in cell B4 which is 46 here.

LEN(B5)-LEN(SUBSTITUTE(B5,”/”,””))) indicates the difference between the two length values. This in turn indicates the number of “/” were removed.

SUBSTITUTE(B5,”/”,”*”,LEN(B5)-LEN(SUBSTITUTE(B5,”/”,””))) substitutes all the slashes (/) is cell B5 with star sign (*) with the instance number from the result of the previous function.

FIND(“*”,SUBSTITUTE(B5,”/”,”*”,LEN(B5)-LEN(SUBSTITUTE(B5,”/”,””)))) finds the position “*” is in the string up until now.

LEN(B5)-FIND(“*”,SUBSTITUTE(B5,”/”,”*”,LEN(B5)-LEN(SUBSTITUTE(B5,”/”,””)))) is the difference between the original string length and the previous position.

Finally, RIGHT(B5,LEN(B5)-FIND(“*”,SUBSTITUTE(B5,”/”,”*”,LEN(B5)-LEN(SUBSTITUTE(B5,”/”,””))))) extracts that number of characters from the right side of the cell.


Method 13 – Match Text in List

We’ll find out the persons who have resigned from the left side of our example. There is a list on the right side of the resigned numbers. The data is in the range B5:D25.

Steps:

  • Select cell E5.
  • Insert the following formula.

=IF(COUNTIF($G$5:$G$25,C5),"Resigned","")

  • Press Enter.

match text formula

  • Double-click the fill handle icon on the bottom-right corner of the cell border.
  • The spreadsheet will look like this.

Read More: How to Remove Partial Data from Multiple Cells in Excel


Method 14 – Change Vertical Data to Horizontal

We will be using the following dataset.

Using the Paste Special Option

  • Select the range that you want to transpose. We have selected the range B4:C10.
  • Press Ctrl + C to copy the range.
  • Select a cell where you want to paste the range. We have selected cell B12.
  • Select the Paste Transposed option from the Paste menu on the Home bar.

paste special for changing vertical data to horizontal

  • This will change vertical columns into horizontal rows in the Excel spreadsheet.

Using the TRANSPOSE Function:

Steps:

  • Select the cell where you want to place the formula.
  • Use the following formula in it.

=TRANSPOSE(B4:C10)

transpose function for changing vertical data to horizontal in data cleaning techniques in excel

  • Press Enter.


Method 15 – Fill Blank Cells

Here’s a sales dataset. We’ll fill the Sales Representative column by duplicating the entries from above.

Using the Fill Command

  • Select cell B6.
  • Go to the Home tab.
  • From the Editing group, click on Fill and then Down.

filling blank cells feature in data cleaning techniques in excel

  • The dataset will look like this now.

  • Repeat the process for all the blank cells and fill out all the cells.

filled up blank cells using feature

Using a Keyboard Shortcut:

  • Select cell B6.
  • Press Ctrl + D on your keyboard.

filling up blank cells with previous values

  • Selecting cell B9 and pressing Ctrl + D will yield the following result.

  • Fill out all the blank values by selecting them and pressing the shortcut.

filled up blank cells using shortcuts


Method 16 – Check the Spelling

Here’s a sample dataset, where we’ll spellcheck column C.

Steps:

  • Select the range C5:C7.
  • Go to the Review tab and select Spelling from the Proofing section. Alternatively, press F7 on your keyboard.

spelling check option in Excel

  • Select the correct suggestion and click on Change to change the value of a particular cell. The errors come in the selection order here.

  • This will change the first error in the dataset.

  • Repeat this process for all the errors and you will have corrected spellings.

spell checks in Excel


Method 17 – Replace or Remove Text

We have a sample dataset of IDs that we need to modify in some way.

Using the Find & Replace Feature:

  • Select the range which you want to modify. In this case, it is C5:C13.
  • Go to the Home tab.
  • Select Find & Replace from the Editing section.
  • Select Replace from the drop-down menu.

replacting text option excel

  • Go to the Replace tab in the pop-up box.
  • Insert the value you want to replace in the Find what field and the value you want to replace it with in the Replace with box.

  • Click Replace All to replace all of the values in the dataset.

hyphens removed using replace option in excel

Utilizing Flash Fill:

  • Write down the final product after removing or replacing the desired value in the first cell. We are replacing the second hyphen in the string with a colon.

  • Start writing the second one manually. As soon as you start writing, Excel will recognize the pattern and start suggesting the output for the rest.

flash fill feature to edit text excel

Note

Excel sometimes suggests the output at the third or fourth entry if the pattern isn’t that obvious.

  • Press Enter.

Using the SUBSTITUTE Function:

  • Select cell C5.
  • Use the following formula in it.

=SUBSTITUTE(B5,"-",":",2)

  • Press Enter.

substitute function to alter text in data cleaning techniques in excel

  • Select the cell again and click and drag the fill handle icon to the end of the column to replicate the formula for the rest of the cells.

Read More: Using Excel to Clean and Prepare Data for Analysis


Method 18 – Add Text to Cells

Let’s add text at the end of the values in the following dataset.

Using the Ampersand (&) Symbol

  • Select cell C5.
  • Use the formula below.

=B5&".mp3"

  • Press Enter.

adding text using ampersand sign

  • Click and drag the fill handle icon to the end of the column to replicate the formula for the rest of the cells.

Applying the Flash Fill Feature:

  • Write down the first intended value manually in cell C5.

  • Start filling out the second one in the dataset. Once you start filling, Excel will suggest the pattern.

adding text using fill command in data cleaning techniques in excel

  • As soon as the suggestion appears, press Enter.

Using the CONCATENATE Function:

  • Select cell C5.
  • Use the following formula in it.

=CONCATENATE(B5,".mp3")

  • Press Enter.

concatenate function to add text in data cleaning techniques in excel

  • Select the cell again and click and drag the fill handle icon to the end of the column to replicate the formula for the rest of the cells.


Method 19 – Fix Trailing Minus Sign

Sometimes while taking data from other sources, the negative values have a trailing minus sign. Here’s an example. Excel won’t recognize these as numbers, so we have to fix them.

Steps:

  • Select the range you want to convert. We have copied it to compare it with the previous one.

  • Go to the Data tab on your ribbon.
  • Select Text to Columns from the Data Tools group section.

fixing trailing signs

  • Click on Finish in the wizard.

fixing trailing minus sign option

  • This will automatically change all the negative values with trailing minus signs to Excel’s negative sign format.

trailing minus sign fixed excel

  • This procedure works because there is a default setting in the Advanced Text Import Settings dialog box.

Download the Practice Workbook


Related Articles

<< Go Back To Data Cleaning in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Kawser Ahmed
Kawser Ahmed

Kawser Ahmed is a Microsoft Excel Expert, Udemy Course Instructor, Data Analyst, Finance professional, and Chief Editor of ExcelDemy. He is the founder and CEO of SOFTEKO (a software and content marketing company). He has a B.Sc in Electrical and Electronics Engineering. As a Udemy instructor, he offers 8 acclaimed Excel courses, one selected for Udemy Business. A devoted MS Excel enthusiast, Kawser has contributed over 200 articles and reviewed thousands more. His expertise extends to Data Analysis,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo