+ Reply to Thread
Results 1 to 7 of 7

Spell Check only Cell that has changed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Spell Check only Cell that has changed

    Hello,
    I am trying to run a VBA to spell check a cell that has been changed and not the whole sheet. I have tried the following....
    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = True
    ' ~~>  Spell check changed cells in column 'D'
        If Target.Column = 4 Then
            Application.EnableEvents = False
                If ActiveCell.Row > 2 Then
                    For Each Cell In Intersect(Target, Columns(4))
                        Selection.CheckSpelling
                    Next
                End If
        Application.EnableEvents = True
        End If
    End Sub
    ....and....
    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = True
    ' ~~>  Spell check changed cells in column 'D'
        If Target.Column = 4 Then
            Application.EnableEvents = False
                If ActiveCell.Row > 2 Then
                        Selection.CheckSpelling
                End If
        Application.EnableEvents = True
        End If
    End Sub
    ....but both check the whole sheet. I have also tried 'Cell.CheckSpelling' instead of 'Selection.CheckSpelling' in both sections but same issue.

    Thank you.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    Hi !

    Try replacing in first code Activecell by Target and Selection by Cell

  3. #3
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: Spell Check only Cell that has changed

    Marc L: Just to confirm, I have changed the code to....
        If Target.Column = 4 Then
            Application.EnableEvents = False
                If Target.Row > 2 Then
                    For Each Cell In Intersect(Target, Columns(4))
                        Cell.CheckSpelling
                    Next
                End If
        Application.EnableEvents = True
        End If
    ....but same issue, it checks the other cells.

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Spell Check only Cell that has changed

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim checkRange As Range
    Dim checkCell As Range
    
    Set checkRange = Application.Intersect(Target, Range("D:D"))
    If checkRange Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    For Each checkCell In checkRange
        If checkCell.Row > 2 Then
            checkCell.CheckSpelling
        End If
    Next checkCell
    Application.EnableEvents = True
    
    End Sub
    WBD
    Office 365 on Windows 11, looking for rep!

  5. #5
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: Spell Check only Cell that has changed

    Thanks WideBoyDixon but it still checks the rest of the document.

  6. #6
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Spell Check only Cell that has changed

    Ah. A little research suggests that checking spelling on a single cell will check the whole sheet. Use a fixed cell that doesn't contain spelling errors and do it like this:

    Private Const CellWithNoErrors = "D1"
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim checkRange As Range
    Dim checkCell As Range
    
    Set checkRange = Application.Intersect(Target, Range("D:D"))
    If checkRange Is Nothing Then Exit Sub
    
    Debug.Print checkRange.Address
    
    Application.EnableEvents = False
    For Each checkCell In checkRange
        If checkCell.Row > 2 Then
            Application.Union(Range(CellWithNoErrors), checkCell).CheckSpelling
        End If
    Next checkCell
    Application.EnableEvents = True
    
    End Sub
    WBD

  7. #7
    Forum Contributor
    Join Date
    11-08-2012
    Location
    Manchester, UK
    MS-Off Ver
    Excel 2016
    Posts
    142

    Re: Spell Check only Cell that has changed

    WBD - thath works great, thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Changing Spell Check language of Vba Spell Checker
    By jhelliar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2021, 03:51 AM
  2. Replies: 1
    Last Post: 10-20-2014, 11:01 AM
  3. spell check changed cells
    By yjbrody in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2009, 04:45 PM
  4. Replies: 1
    Last Post: 02-03-2006, 04:30 PM
  5. [SOLVED] Spell Check an Unlocked Cell in a Protected Spreadsheet
    By Jill E in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  6. Spell Check an Unlocked Cell in a Protected Spreadsheet
    By Jill E in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 07:05 AM
  7. [SOLVED] Spell Check an Unlocked Cell in a Protected Spreadsheet
    By Jill E in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1