Check Spelling Method For Single Cell
-
-
-
Re: Check Spelling Method For Cell Only
That can be irritating... but I think I actually take sides with MS on this implementation decision.
By default, if the spellchecker detects one cell is selected, it assumes you want the whole sheet checked. Basically trying to account for silly users who are likely to forget and do a spell check with a single cell selected. In which case, they'd complain "I did run a spellcheck and Excel didn't find anything."
Since any range selection with a cell count greater than 1 would pass the test, I'd just pick a dummy cell that I know will always be empty and include it in the spellcheck range.
-
Re: Check Spelling Method For Single Cell
This code debugs on the Union part. Can mutli-worksheet ranges not be unioned?
Code
Display MoreDim cell1 As Range Dim cell2 As Range Dim cell3 As Range Dim cell4 As Range Dim cell5 As Range Dim cell6 As Range Dim cell7 As Range Dim cell8 As Range Dim cell9 As Range Dim cell10 As Range Dim cell11 As Range Dim cell12 As Range Dim cell13 As Range Dim cell14 As Range Dim cell15 As Range Dim cell16 As Range Dim cell17 As Range Dim cell18 As Range Dim cell19 As Range Dim cell20 As Range Dim cell21 As Range Set cell1 = Worksheets("Section IV,V&VI-MUST COMPLETE").Range("b7") Set cell2 = Worksheets("Section IV,V&VI-MUST COMPLETE").Range("b12") Set cell3 = Worksheets("Section II&III- MUST COMPLETE").Range("b53") Set cell4 = Worksheets("Section II&III- MUST COMPLETE").Range("b55") Set cell5 = Worksheets("Section II&III- MUST COMPLETE").Range("b59") Set cell6 = Worksheets("Section II&III- MUST COMPLETE").Range("b61") Set cell7 = Worksheets("Section II&III- MUST COMPLETE").Range("b65") Set cell8 = Worksheets("Section II&III- MUST COMPLETE").Range("b67") Set cell9 = Worksheets("Section II&III- MUST COMPLETE").Range("b71") Set cell10 = Worksheets("Section II&III- MUST COMPLETE").Range("b73") Set cell11 = Worksheets("Section II&III- MUST COMPLETE").Range("b77") Set cell12 = Worksheets("Section II&III- MUST COMPLETE").Range("b79") Set cell13 = Worksheets("Section II&III- MUST COMPLETE").Range("b87") Set cell14 = Worksheets("Supplemental").Range("b20") Set cell15 = Worksheets("Supplemental").Range("b22") Set cell16 = Worksheets("Supplemental").Range("b26") Set cell17 = Worksheets("Supplemental").Range("b28") Set cell18 = Worksheets("Supplemental").Range("b32") Set cell19 = Worksheets("Supplemental").Range("b34") Set cell20 = Worksheets("Supplemental").Range("B38") Set cell21 = Worksheets("Supplemental").Range("b40") Application.Union(cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10 _ , cell11, cell12, cell13, cell14, cell15, cell16, cell17, cell18, cell19, cell20 _ , cell21).CheckSpelling
-
Re: Check Spelling Method For Single Cell
Hmm, that seems a very long winded way of doing it.
Why not define one named range for all the cells to be checked on each sheet. eg 3 sheets, 3 names, then run the spell check three times.
Then your code would be about 5 lines, and no union function reqd.Also, you've used relative references (no $ signs) which may make the behaviour a bit erratic
-
Re: Check Spelling Method For Single Cell
Bruce,
Yea I knew the way I wrote the code was long...could you give me an example of what you're talking about? -
-
Re: Check Spelling Method For Single Cell
Quote from BruceMuttonHmm, that seems a very long winded way of doing it.
Why not define one named range for all the cells to be checked on each sheet. eg 3 sheets, 3 names, then run the spell check three times.
Then your code would be about 5 lines, and no union function reqd.Also, you've used relative references (no $ signs) which may make the behaviour a bit erratic
The purpose of the union in the first place was a workaround to the spellcheck entire sheet if the spellcheck range is a single cell. So no, you'll still need the union workaround if checking a single cell on a sheet.
-
Re: Check Spelling Method For Single Cell
OK. Aaron, thanks for the initial code. What I decided was I would use a list of cells that need to be checked. So, how do I check these specific cells? I tried that with the above code, but that didn't work.
-
Re: Check Spelling Method For Single Cell
Quote from kpfunfBruce,
Yea I knew the way I wrote the code was long...could you give me an example of what you're talking about?A more efficient way to do that would be...
Code
Display MoreSub test() With Worksheets("Section IV,V&VI-MUST COMPLETE") .Range("B7,B12").CheckSpelling End With With Worksheets("Section II&III- MUST COMPLETE") .Range("B53,B55,B59,B61").CheckSpelling End With With Worksheets("Section II&III- MUST COMPLETE") .Range("B20,B22,B26,B28").CheckSpelling End With End Sub
Where if the situation should occur that you have a single cell to spellcheck, you just include a reference to an empty dummy cell.
However, I'm not crazy about the hardcoded range references. The suggestion to assign workbook defined names to the non-contiguous ranges of each sheet does make more sense. ...and that way you don't have to worry about updating code if you need to insert rows/columns cuz the defined names would update automatically.
You'd just Ctrl-Click on each cell of a given sheet to create the non-cont spellcheck range and then on the main menu select: Insert|Name|Define and choose an appropriate name "Spellcheck1". Repeat for each sheet and your code simplifies to...
CodeSub test() Range("SpellCheck1").CheckSpelling Range("SpellCheck2").CheckSpelling Range("SpellCheck3").CheckSpelling End Sub
...and you don't have to worry about updating the range refs if rows/cols are inserted/deleted.
You could avoid the union issue completely as long as the defined names all contain more than a single cell. If you wanted to be extra safe, I s'pose you could still include a dummy cell union.
-
Re: Check Spelling Method For Single Cell
Thanks Aaron.
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!