Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Spell Check with VBA

February 12, 2015 Marcus Small

I recently responded to an interesting post where someone asked for assistance with some code to check spelling for a words in specific cells. The poster wanted the cells with the errors to have the font highlighted in red if the word was spelt incorrectly. Here is the code I came up with.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Myrange As Range
If Not Intersect(Target, Range("L10,L14,L29")) Is Nothing Then
   For Each Myrange In Union([L10], [L14], [L29])
      If Application.CheckSpelling(Myrange) = False Then
         Myrange.Font.Color = vbRed
      Else: Myrange.Font.Color = vbBlack
      End If
   Next
End If
End Sub

As it turned out the person wanted something a bit more complex.  They wanted the whole sheet to be checked and when it was checked to highlight only the words spelt incorrectly.  So if multiple words were spelt incorrectly then only highlight the words in a specific cell which were wrong.  Enter my friend Narayan (who is also an Excel Ninja on Chandoo’s site) he came up with the following which I have altered only slightly. 

Private Sub Worksheet_Change(ByVal Target As Range)
Call CheckSpelling1(Target)
End Sub

Sub CheckSpelling1(r As Range)
Dim rng As Range
Dim ar() As String
Dim i As Long
Dim j As Long
With Application.SpellingOptions
   .IgnoreCaps = True
   .IgnoreFileNames = True
   .IgnoreMixedDigits = True
End With

   For Each rng In r
      If Not rng.HasFormula And VarType(rng.Value) = vbString Then
         ar = Split(Replace(rng.Value, Chr(160), " "), " ")
         j = 1
         rng.Font.ColorIndex = xlColorIndexAutomatic
         For i = 0 To UBound(ar)
            If Not Application.CheckSpelling(ar(i)) Then
               rng.Characters(j, Len(ar(i))).Font.ColorIndex = 3
            End If
            j = j + 1 + Len(ar(i))
         Next i
      End If
   Next rng
End Sub

The coding above goes in the worksheet where you intend to have the spelling checked automatically. It will highlight misspelt words in red.

CheckSpelling.xls

Tags spelling excel vba
← Excel Like a BossUpdate Caption with VBA →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.