Results 1 to 12 of 12

Thread: Insert a function to delete any words with less than 3 characters in a VBA code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    snb
    Guest
    I'd use this macro instead of Pascale Paquin's macro:

    Sub M_snb()
      sn = UsedRange.Columns(1)
            
      For j = 1 To UBound(sn)
        c00 = c00 & " " & sn(j, 1)
      Next
      sn = Split(Application.Trim(c00))
        
      For j = 0 To UBound(sn)
        If Len(sn(j)) < 3 Then sn(j) = ""
      Next
      c00 = Application.Trim(Join(sn))
      sn = Split(c00)
      ReDim sp(UBound(sn), 14)
        
      With CreateObject("scripting.dictionary")
        For j = 0 To UBound(sn)
          c01 = sn(j)
          st = Filter(sn, c01)
          If UBound(st) > 0 Then .Item(c01 & "~1") = UBound(st) + 1
          For jj = 1 To 4
            If j + jj > UBound(sn) Then Exit For
            c01 = c01 & " " & sn(j + jj)
            st = Split(c00, c01)
            If UBound(st) > 1 Then .Item(c01 & "~" & jj + 1) = UBound(st)
          Next
        Next
           
        For j = 0 To 4
          st = Filter(.keys, "~" & j + 1)
          sp(0, 3 * j) = j + 1 & " WORD"
          sp(0, 3 * j + 1) = "COUNT"
          For jj = 0 To UBound(st)
            sp(jj + 1, 3 * j) = Left(st(jj), Len(st(jj)) - 2)
            sp(jj + 1, 3 * j + 1) = .Item(st(jj))
          Next
        Next
      End With
         
      Cells(1, 20).Resize(UBound(sp), 15) = sp
      For j = 0 To 4
        Cells(2, 20 + 3 * j).CurrentRegion.Sort Cells(2, 20 + 3 * j + 1), 2
      Next
    End Sub
    Last edited by snb; 06-01-2022 at 04:50 AM.

Posting Permissions

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