+ Reply to Thread
Results 1 to 4 of 4

Typo generator in Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2015
    Location
    Delhi
    MS-Off Ver
    Office 2013
    Posts
    5

    Typo generator in Excel

    Hello,

    I need to create a list of typos basis a starting list. Would anyone have any pointers on how do I get started on this?

    eg for the following

    Adam
    Bob
    Charlie

    generate as many typos as possible like so in the succeeding columns, like so

    Adam, aadm, adma, ama, adm etc
    Bob, bbo, obb
    Charlie, Charlei, cahrlie

    I tried doing this though an online tool, but it will take way too long for the 1000 odd words that I need to do this for.
    http://tools.seobook.com/spelling/keywords-typos.cgi

    Any help is much appreciated.

    CP

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,873

    Re: Typo generator in Excel

    As the number of generated typos can be quite large, the proposition below is for original words inserted in first row of the sheet (not in column A - use copy and paste special with transpose).
    I used just 4 types of typos - missing letter, Czech mistake (error in sequence of two neighbours), random replacement of one letter and random inserton of one letter. Of course one can use many more of them.
    See the working model in attachment, and the code below:
    Sub typogenerator()
    Dim i As Long, j As Integer, l As Integer, k As Long, proper As String
    Dim typos() As String
    Application.ScreenUpdating = False
    ReDim typos(1 To 1)
    For i = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
      k = 1
      proper = Cells(1, i)
    'missed one letter
      For j = 1 To Len(proper)
        ReDim Preserve typos(1 To k)
        typos(k) = Left(proper, j - 1) & Mid(proper, j + 1)
        k = k + 1
      Next j
    'Czech mistake
      For j = 1 To Len(proper) - 1
        ReDim Preserve typos(1 To k)
        typos(k) = Left(proper, IIf(j > 1, j - 1, 0)) & Mid(proper, j + 1, 1) & Mid(proper, j, 1) & Mid(proper, j + 2)
        k = k + 1
      Next j
    'any character replaced with random one
      For j = 1 To Len(proper)
        For l = 97 To 122 ' you may wish to try also 32 To 126
          ReDim Preserve typos(1 To k)
          typos(k) = Left(proper, j - 1) & Chr(l) & Mid(proper, j + 1)
          k = k + 1
        Next l
      Next j
    'random char inserted on any position between original
      For j = 1 To Len(proper) + 1
        For l = 97 To 122 ' you may wish to try also 32 To 126
          ReDim Preserve typos(1 To k)
          typos(k) = Left(proper, j - 1) & Chr(l) & Mid(proper, j)
          k = k + 1
        Next l
      Next j
    'add next typos here similar way if you need
    
    'write horizontal array in vertical way into a sheet
      Cells(2, i).Resize(k - 1, 1).Value = Application.Transpose(typos)
    'remove duplicates, because inserting _a_ into Adam can leed to Ad_a_am and Ada_a_m etc.
      Cells(1, i).Resize(k, 1).RemoveDuplicates Columns:=1, Header:=xlNo
    Next i
    End Sub
    Attached Files Attached Files
    Last edited by Kaper; 08-28-2015 at 03:43 AM. Reason: Huh, I found typo in my text too: Czech mistale :lol:
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    08-27-2015
    Location
    Delhi
    MS-Off Ver
    Office 2013
    Posts
    5

    Re: Typo generator in Excel

    Just for the sake of completeness. The following code, transposes the data and writes it straight into a CSV file.

    Sub WriteFile()
    
      Dim ColNum As Integer
      Dim Line As String
      Dim LineValues() As Variant
      Dim OutputFileNum As Integer
      Dim PathName As String
      Dim RowNum As Integer
      Dim SheetValues() As Variant
    
      PathName = Application.ActiveWorkbook.Path
      OutputFileNum = FreeFile
    
      Open PathName & "\Test.csv" For Output Lock Write As #OutputFileNum
    
      'Print #OutputFileNum, "Field1" & "," & "Field2"
    
      SheetValues = Sheets("RawData").Range("A1:C249").Value
    
    Dim RowMax
    RowMax = UBound(SheetValues)
    Dim ColMax
    ColMax = 3
    ReDim LineValues(1 To RowMax)
    
      For ColNum = 1 To ColMax
        For RowNum = 1 To RowMax
          LineValues(RowNum) = SheetValues(RowNum, ColNum)
        Next
        Line = Join(LineValues, ",")
        Print #OutputFileNum, Line
      Next
    
      Close OutputFileNum
    
    End Sub
    Last edited by chiragpatnaik; 09-11-2015 at 05:23 AM. Reason: write to file

  4. #4
    Registered User
    Join Date
    08-27-2015
    Location
    Delhi
    MS-Off Ver
    Office 2013
    Posts
    5

    Re: Typo generator in Excel

    Dear Kaper,

    That's excellent. This is what I was looking for. Just to let you know, I was looking to build a typo dictionary to feed a SOLR deployment. Which is why I needed it in rows which could be saved as a CSV. This eases a lot of pain at my end. Really appreciate it.

    CP
    Last edited by chiragpatnaik; 08-28-2015 at 12:31 AM.

+ 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. Need a way to find typo's in an invoice number
    By salestemp in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-12-2015, 04:02 PM
  2. Typo makes people lots of money
    By NBVC in forum The Water Cooler
    Replies: 2
    Last Post: 06-01-2011, 05:47 PM
  3. Reduce typo's
    By excelrealnoob in forum Excel General
    Replies: 1
    Last Post: 07-16-2009, 11:55 AM
  4. Excel 2007 : Typo in DDE formula is being saved
    By MdrNate in forum Excel General
    Replies: 2
    Last Post: 06-24-2008, 10:38 AM
  5. [SOLVED] Excel Sheet generator
    By Tomasz Klim in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 06-06-2006, 03:35 PM
  6. How to make an exponential series?:typo
    By Vasant Nanavati in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 AM
  7. Typo error I think - Calculating the Difference Between Hours
    By aph in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-26-2005, 12:05 PM

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