Public Sub NhayCaTung()
Dim Vung, Cot, Buoc, Dk As String, SoSanh As String, Mg(), I As Long, J As Long, Dem As Long
Vung = Range([a4], [a10000].End(xlUp)).Resize(, 101).Value
Cot = InputBox("Nhâp ký tu dai dien côt", "Nhâp côt", , , , "DEMO.HLP", 10)
Buoc = Val(InputBox("Nhâp sô buoc nhay", "Sô buoc", , , , "DEMO.HLP", 10))
Cot = VBA.Asc(UCase(Cot)) - 64
ReDim Mg(1 To UBound(Vung), 1 To 1)
For I = 1 To UBound(Vung)
For J = Cot + Buoc To 101 Step Buoc
Dk = IIf(Vung(I, Cot) = vbNullString, "A", "B")
SoSanh = IIf(Vung(I, J) = vbNullString, "A", "B")
If Dk = SoSanh Then
Dem = Dem + 1
Else
Dem = Dem
Mg(I, 1) = Dem
Exit For
End If
Next J
Mg(I, 1) = Dem
Dem = 0
Next I
Cells(4, 104).Resize(UBound(Vung), 1) = Mg
End Sub