Tag: clean data in Excel

  • Top 10 Ways to Clean Data in Excel Easily (With Examples)

    Data cleaning is crucial when working with large datasets in Excel. Raw data often contains errors like extra spaces, duplicates, inconsistent formatting, or missing values. Cleaning data ensures accurate analysis, professional reports, and better decision-making. Here’s a step-by-step guide to the top 10 ways to clean data in Excel with real examples.


    1. Remove Extra Spaces with TRIM Function

    Extra spaces often appear when importing data from other sources. These spaces can cause formulas to fail or make data look inconsistent.

    How to Apply:

    1. Suppose cell A1 contains " John Doe " (with spaces at start and end).
    2. Use the formula: =TRIM(A1)
    3. Excel removes all leading, trailing, and extra spaces between words.

    Example:

    OriginalCleaned
    ” John Doe ““John Doe”

    2. Convert Text to Numbers

    Sometimes numeric values are stored as text, which can break calculations.

    How to Apply:

    1. Suppose cell B1 has "100" stored as text.
    2. Use the formula: =VALUE(B1)
    3. Excel converts text to a number that can be used in calculations.

    Example:

    OriginalConverted
    “100”100

    Alternative: Select the column → Click Data > Text to Columns → Finish. This also converts text numbers into actual numbers.


    3. Remove Duplicates

    Duplicate entries can skew analysis and reports.

    How to Apply:

    1. Select the dataset.
    2. Go to Data → Remove Duplicates.
    3. Choose the columns to check duplicates.
    4. Click OK.

    Example:

    NameCity
    John DoeDelhi
    Jane SmithMumbai
    John DoeDelhi

    ✅ Now only unique entries remain.


    4. Use Find and Replace for Bulk Changes

    Correct common errors or format data quickly.

    How to Apply:

    1. Press Ctrl + H.
    2. In Find What, type the incorrect data (e.g., “Indai”).
    3. In Replace With, type the correct data (e.g., “India”).
    4. Click Replace All.

    Example:

    OriginalCorrected
    IndaiIndia

    This method also works for symbols, extra characters, or formatting changes.


    5. Standardize Text Case (PROPER, UPPER, LOWER)

    Inconsistent capitalization can make data look unprofessional.

    Formulas:

    • =PROPER(A1) → Capitalizes first letter of each word.
    • =UPPER(A1) → Converts to uppercase.
    • =LOWER(A1) → Converts to lowercase.

    Example:

    OriginalProper CaseUpper CaseLower Case
    john doeJohn DoeJOHN DOEjohn doe

    6. Handle Missing Data

    Missing values can affect calculations and charts.

    Methods:

    1. Replace with 0: =IF(A1="","0",A1)
    2. Replace with average: =IF(A1="",AVERAGE($A$1:$A$100),A1)

    Example:

    ValueCleaned
    100100
    0

    7. Text-to-Columns for Splitting Data

    Useful when multiple values are in a single column (e.g., Name, City, State).

    How to Apply:

    1. Select the column.
    2. Go to Data → Text to Columns.
    3. Choose Delimited → Select delimiter (comma, space, etc.).
    4. Click Finish.

    Example:

    OriginalNameCityState
    John Doe, Delhi, DLJohn DoeDelhiDL

    8. Use SUBSTITUTE for Text Errors

    Replace unwanted characters, symbols, or words automatically.

    Formula:

    =SUBSTITUTE(A1,"-","")
    

    Example:

    OriginalCleaned
    123-456-78901234567890

    9. Use Flash Fill for Quick Formatting

    Automatically fills a column based on the pattern you provide.

    How to Apply:

    1. Type the desired output in one cell.
    2. Press Ctrl + E to auto-fill the rest.

    Example:

    OriginalFirst Name
    John DoeJohn
    Jane SmithJane

    ✅ Flash Fill extracts first names automatically.


    10. Data Validation to Prevent Future Errors

    Prevent users from entering invalid data in a column.

    How to Apply:

    1. Select the column.
    2. Go to Data → Data Validation.
    3. Set criteria (e.g., numbers between 1–100, date range, dropdown list).

    Example:

    • Prevents typing letters in a numeric score column.
    • Creates dropdown menus for cities or product categories.

    Conclusion

    Cleaning data in Excel is essential for accurate reporting, analysis, and decision-making. By mastering these 10 methods—TRIM, Remove Duplicates, Flash Fill, Data Validation, and more—you can save time and avoid errors.

    ✅ Pro Tip: Combine methods like TRIM + Remove Duplicates + Data Validation for maximum efficiency.


  • Extract Numbers from Text in Excel Using VBA – Works for Indian & European Formats

    🧾 Scenario:

    At Shree Tech Pvt. Ltd., Priya is a finance executive handling a lot of messy Excel data received from multiple vendors and sales teams across India and Europe.

    One day, she encounters a peculiar problem.
    In the “Remarks” column, instead of clean numbers, she sees entries like:

    • "₹3,499 paid in full"
    • "1.250,50 EUR"
    • "Advance of 7500.00 received"
    • "Amount is Rs. 2,50,000/-"

    She needs to extract only the numeric value from these cells, but Excel’s built-in tools can’t help much.

    That’s when her teammate, Rohit, a skilled MIS guy, steps in with a magic wand—a custom VBA function called getNumber.


    🧙‍♂️ The Magic VBA Function: getNumber

    Here’s the full code Rohit shares:

    vbaCopyEditPublic Function getNumber(fromThis As Range) As Double
        'Extract the number from a cell and return it.
        Dim retVal As String
        Dim ltr As String, i As Integer, european As Boolean
        
        retVal = ""
        getNumber = 0
        european = False
        
        On Error GoTo last
        'Check if the range contains European format number i.e. , for decimal point
        If fromThis.Value Like "*.*,*" Then
            european = True
        End If
        
        For i = 1 To Len(fromThis)
            ltr = Mid(fromThis, i, 1)
            If IsNumeric(ltr) Then
                retVal = retVal & ltr
            ElseIf ltr = "." And (Not european) And Len(retVal) > 0 Then
                retVal = retVal & ltr
            ElseIf ltr = "," And european And Len(retVal) > 0 Then
                retVal = retVal & "."
            End If
        Next i
        getNumber = CDbl(retVal)
    last:
    End Function
    

    🔍 Line-by-Line Breakdown with Office-style Explanation


    ✅ What it does:

    Extracts numbers embedded in any text, whether the number is in Indian format (e.g., 2,50,000) or European format (e.g., 1.234,56).


    🎬 Scene-by-Scene Breakdown:


    🪪 Characters:

    • fromThis: The Excel cell that has the mixed content (like "Total ₹4,500.50 paid").
    • retVal: The string variable used to slowly build the extracted number.
    • european: A flag to detect if commas are used as decimal separators (common in European format like "1.234,56").

    💡 Step 1: Initialization

    vbaCopyEditretVal = ""
    getNumber = 0
    european = False
    

    Rohit clears any previous values and sets the assumption that the format is not European by default.


    🧠 Step 2: Detecting European Format

    vbaCopyEditIf fromThis.Value Like "*.*,*" Then
        european = True
    End If
    

    This checks if the cell contains both a dot and a comma (e.g., "1.234,56"). If yes, it assumes the comma is the decimal point (European format).

    Priya’s vendor from Germany sent "1.250,50 EUR". This line sets european = True.


    🔁 Step 3: Loop Through Each Character

    vbaCopyEditFor i = 1 To Len(fromThis)
        ltr = Mid(fromThis, i, 1)
    

    The loop reads the text character by character. If the cell has "Amount ₹2,50,000.75", it starts reading "A", "m", "o", etc.


    🔢 Step 4: Build the Numeric Part

    Here’s the logic Rohit uses:

    vbaCopyEditIf IsNumeric(ltr) Then
        retVal = retVal & ltr
    

    If the character is a digit (0–9), it adds to the final number string.

    Then:

    vbaCopyEditElseIf ltr = "." And (Not european) And Len(retVal) > 0 Then
        retVal = retVal & ltr
    

    If it’s a . and it’s not European format, it’s added as the decimal point.

    vbaCopyEditElseIf ltr = "," And european And Len(retVal) > 0 Then
        retVal = retVal & "."
    

    If it’s European format, then the comma , is converted into a dot .—because VBA/Excel understand . as the decimal point.

    So "1.234,56" becomes "1234.56" internally.


    💾 Step 5: Convert the Final String to Number

    vbaCopyEditgetNumber = CDbl(retVal)
    

    Finally, the retVal string, say "4500.75", is converted into a Double data type using CDbl.


    🛑 Step 6: Error Handling

    vbaCopyEditOn Error GoTo last
    ...
    last:
    End Function
    

    If there’s any weird data or unexpected character that crashes the function, it fails silently and exits.


    📦 Examples: How It Works in Practice

    Cell ContentOutputExplanation
    "Rs. 4,500.75 paid"4500.75Indian format, plain extraction
    "1.234,56 EUR"1234.56European format, comma → dot
    "Amount: ₹2,50,000/-"250000Only digits picked, commas ignored
    "Advance of 7500.00 received"7500.00Straight number pulled out
    "Zero balance"0No digits found, returns 0

    ✅ Where to Use This Function

    Use =getNumber(A2) in any cell, where A2 contains your text with numbers.


    🎁 Bonus Tip from Rohit:

    You can paste this VBA code into your Excel file by pressing:

    1. ALT + F11 → Open VBA editor
    2. Insert > Module
    3. Paste the code
    4. Save as Macro-Enabled Workbook (.xlsm)

    Download Number Extraction VBA Function File