How to solve a problem on VBA, in the cell a string is set for example "Hello World!" you need to print all the letters that are in the most words in the string.
So far, he stopped at the stage of finding matches in different words
Public Function CountChar(str1 As String, str2 As String) As Integer Dim i As Integer Dim k As Integer 'Dim str1 As String 'Dim str2 As String 'str1 = Range("A1").Value 'str2 = " " k = 0 For i = 1 To Len(str1) If StrComp(Mid(str1, i, 1), str2, vbTextCompare) = 0 Then k = k + 1 End If Next CountChar = k End Function Sub sovpad() Dim lsRow&, i&, j&, arr, s$ Dim k As Integer Dim z As Integer Dim x As Integer Dim g As Integer Dim h As Integer Dim count As Integer Dim st As String Dim RusAlpha As Variant Dim EngAlpha As Variant Dim iLastRow As Long x = 2 EngAlpha = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z") RusAlpha = Array("à", "á", "â", "ã", "ä", "å", "¸", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ") lsRow = Range("A1").CurrentRegion.Rows.count For i = 1 To lsRow arr = Split(Cells(i, 1), " ") For j = LBound(arr) To UBound(arr) s = arr(j) If Cells(i, 2) Like s Then Cells(i, 4) = "": Exit For Else: Cells(i, 4) = "" For k = 0 To 32 st = RusAlpha(k) count = CountChar(s, st) If (count > 0) Then Range("A" & x).Value = st Range("B" & x).Value = CountChar(s, st) 'MsgBox st & CountChar(s, st) x = x + 1 End If Next k For z = 0 To 25 st = EngAlpha(z) count = CountChar(s, st) If (count > 0) Then Range("A" & x).Value = st Range("B" & x).Value = CountChar(s, st) 'MsgBox st & CountChar(s, st) x = x + 1 End If Next z Range("A" & x).Value = " " Range("B" & x).Value = " " Next j Next i iLastRow = Cells(Rows.count, 1).End(xlUp).Row 'MsgBox iLastRow For g = 2 To iLastRow For h = 2 To iLastRow If (Range("A" & g).Value = Range("A" & h)) Then 'MsgBox Range("A" & g).Value End If 'MsgBox g Next h Next g End Sub
CountCharfunctionCountCharuse not a cycle for each letter of a line, butInStr, because, as follows from the assignment, it is only important to have a letter in the word, and not how many times it occurs in it. - Edward Izmalkov