excel database to auto correct what i typing on textbox

mohamedtaha500

New Member
Joined
Jun 21, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
hello guys

i have an idea but i can't do it by my self

I made sheet, with column "A" wrong word spelling and column "b" for correct spilling also i can put full sentences and correct it in column "B"
and made userform with textbox put this code inuserform

VBA Code:
Private Sub TextBox1_Change()
Change
End Sub

Private Sub UserForm_Activate()
    vb_enable_event = True
    Activate
End Sub

and made new module for this code

VBA Code:
Global d As Scripting.Dictionary
Global vb_enable_event As Boolean

Public Sub Change()
    If vb_enable_event = False Then Exit Sub
    
    vb_enable_event = False
    Dim text As String
    text = UserForm1.TextBox1.Value
    
    For Each Key In d.Keys()
        text = Replace(text, Key, d(Key), , , vbTextCompare)
    Next Key
    
    UserForm1.TextBox1.Value = text
    vb_enable_event = True
End Sub

Public Sub Activate()
    Set d = New Scripting.Dictionary
    Dim last_row As Long, i As Long
    last_row = Sheet1.UsedRange.Rows.Count
    d.RemoveAll
    For i = 2 To last_row
        If Sheet1.Cells(i, 1).Value <> "" Then
            d.Add Sheet1.Cells(i, 1).Value, Sheet1.Cells(i, 2).Value
        End If
    Next
End Sub

this code is work perfect but there is dumb problem

The problem with this code is that it replaces the word as soon as it finds it separately in the database, even though there is the same word inside the sentence of the code, it tracks it at the same time. If the code changes the word, the code will fail to match the sentence because a word within the sentence has been corrected, and this will lead to failure The sentence because it is not completely identical to a sentence in the database, and that is why we need code that does not correct the single word as long as the code follows the sentence until it is sure that it was completely written correctly and says to replace it. By correcting the word that he left without correcting, because that is the correct procedure. He left the word without replacing it because it is within a sentence that is currently being tracked. With these words, I do not say that he never replaces a word as long as he finds it within a sentence, but I say that he does not replace the word in the event that it is tracking a sentence. Basically, let's explain it through an example. There are 3 data and correct them in the database.
The first statement in the first column is "rad" and corrected in the second column is "read" like this
The second statement is "mohmd rad the bok" and corrected by "mohamed read the book" in this way
The third statement is ?mohmd? and its correction is ?mohamed? in this way
Now we will start typing in the text box
And we write the first word, and let it be "mohmd" Here we will have two cases, either I will complete the sentence "mohmd rad the bok" or I will write something else that does not match the sentence in the database here. I do not want the code to replace the word "mohmd" before checking whether I will complete The sentence, or I will write something else, because if the code replaces the word ?mohmd? with the word ?mohamed? and I complete the sentence in this way ?mohmd rad the bok? then the code will not find a match and did not replace the word and the same idea also does not change the word ?rad? Because he is currently tracking the sentence "mohmd rad the bok". If he changes the word "rad", the sentence will not be identical. So in this example, I do not want the code to replace the word "mohmd" or the word "rad" until I complete the sentence if I write "the bok". And there is no other match in the database that completely replaces the sentence. If I don't type "the bok" and write anything else, the code understands that there is no match with the sentence and returns to correct the words it left out.

Can any one help me, the mobile keyboard skip this problem by prevent user from put space in the shortcut
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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