VB Excel macro help needed

Status
Not open for further replies.

Drizzt321

Ars Legatus Legionis
34,935
Subscriptor++
So, it's been forever since I did any VB, and it never was very much, so here I am!

So what I'm trying to do is take a comma separate String, split it, and then reduce it, removing duplicate consecutive values. So "2,2,2,1,1" would become "2,1", or "3,3,3,2,3,3,3" would become "3,2,3".

It looks like it should work, but when it gets to the "If currentVal.equals(prevVal) = False Then", it his a runtime error 424, 'Object required'.

Help! My job depends on this! Ok, so not really, but I am getting incredibly frustrated since I'm fumbling around with this, and I'm fine dealing with raw sockets or fancy threading in Java, yet can't get something simple in VB to work.

Code:
Sheets("Sheet1").Select
Range("I1").Select

Dim data() As String
Dim currentVal, prevVal As String
Dim output As String
Dim temp As Boolean

Do Until Selection.Value = ""
        data = Split(Selection, ",")
        output = ""
        prevVal = ""
        For Each elem In data
            currentVal = CStr(elem)
            If currentVal.equals(prevVal) = False Then
            output = output + elem + ","
            End If
        Next elem
        Selection.Value = output
        Selection.Offset(1, 0).Select
Loop
 
Status
Not open for further replies.