Getting a vba to only apply to a pre defined range

hnt007

Board Regular
Joined
Dec 18, 2021
Messages
98
Office Version
  1. 365
Platform
  1. MacOS
Hello and thank you so much for your help!

How can I update the following code to ONLY apply to the range D8:D1000?

Public Sub CheckSheetSpelling()
Dim MySheet As Object, MyCell As Range
Dim i As Integer, j As Integer
Dim MySentence As String, MyWord As String


Set MySheet = ActiveSheet

For Each MyCell In MySheet.UsedRange
If MyCell.Value <> MyCell.Formula Then GoTo NextCell:
If Application.CheckSpelling(MyCell.Value) Then GoTo NextCell:

MySentence = " " & MyCell.Value
i = 2
While i < Len(MySentence)
If Mid(MySentence, i - 1, 1) = " " And Mid(MySentence, i, 1) <> "" Then
j = InStr(i, MySentence, " ") - 1
If j = -1 Then j = Len(MySentence)
MyWord = Mid(MySentence, i, j - i + 1)
If Not Application.CheckSpelling(MyWord) Then
With MyCell.Characters(Start:=i - 1, Length:=j - i + 1).Font
.Underline = xlUnderlineStyleNone
.Color = RGB(255, 0, 0)
End With
End If
i = j + 1
End If
i = i + 1
Wend

NextCell:
Next MyCell

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi
Simply

VBA Code:
For Each MyCell In MySheet.UsedRange
To
VBA Code:
For Each mycell In MySheet.Range("D8:D1000")
 
Upvote 0
Solution
You are very welcome
And thank you for the feedback
Be happy and safe
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top