split function for Excel 2003

J

Janis

Excel 2003 doesn't have the split function. I got this macsplit function
from the microsoft web pages. It colors the cell where there are dupes but I
would like to capture the number of the duplicate program numbers as well.
There is a message that gives the v(ith) iteration of the split but I can't
figure out how to capture that number?
I put in the lines that are commented out, I was trying to store the v(i)
value in S but the compiler says it is a mismatch type or something. Let me
know if you have any ideas.
I think since the cell is an object but v(i) is not an object that is why
the compiler objects but I don't otherwise know how to store the iteration
values.
THANKs,

Sub CkforDupes()

Dim rng As Range, cell As Range
Dim i As Long, c1 As Long
Dim v
Dim iRow As Integer
Dim s
Set rng = Range("D1", Range("D65536").End(xlUp))


For Each cell In rng
v = MACSplit(cell.Text, ",")

For i = LBound(v) To UBound(v)
'Debug.Print "v:"; v(i)

c1 = Application.CountIf(rng, "*" & v(i) & "*")
If c1 > 1 Then ' it should be 1 to match itself
MsgBox v(i) & " :possible dups"
iRow = ActiveCell.Row
's = v(i)
'Debug.Print s
'.Cells(iRow, 27).Value = s
''Debug.Print "v(i): ("; i; ")"; v(i)
cell.Interior.ColorIndex = 3
End If
Next
Next

End Sub
Function MACSplit(s As String, s3 As String)
Dim v As Variant, sChr As String
Dim S1 As String, s2 As String
Dim cnt As Long
Dim i
ReDim v(0 To 0)
S1 = Trim(s)
s2 = ""
If InStr(1, S1, s3, vbTextCompare) = 0 Then
v(0) = S1
MACSplit = v
Exit Function
End If
cnt = -1
For i = 1 To Len(S1)
sChr = Mid(S1, i, 1)
If sChr = s3 Then
cnt = cnt + 1
ReDim Preserve v(0 To cnt)
v(UBound(v)) = s2
s2 = ""

Else
s2 = s2 & sChr
End If
Next
If s2 <> "" And s2 <> s3 Then
cnt = cnt + 1
ReDim Preserve v(0 To cnt)
v(UBound(v)) = s2
End If
MACSplit = v
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top