Dear Team
Hello and Hopping for your Good Health and Safety.
Please note that I want to remove some repeating items from an array.
My array shown below:
Ary(0) = “empty”
Ary(1) = “cat”
Ary(2) = “empty”
Ary(3) = “empty”
Ary(4) = “dog”
Ary(5) = “rate”
Ary(6) = “hen”
and after the execution of the macro I should get following:
Ary_cln(0) = “cat”
Ary_cln(1) = “dog”
Ary_cln(2) = “rate”
Ary_cln(3) = “hen”
From the internet I got a solution which is not working. Please help me out the code is shown below:
Sub test
Dim Ary(0 to 6) As String
Ary(0) = "empty"
Ary(1) = "cat"
Ary(2) = "empty"
Ary(3) = "empty"
Ary(4) = "dog"
Ary(5) = "rate"
Ary(6) = "hen"
Dim Ary_cln() As String
ReDim Ary_cln(0 To 6)
For i = LBound(Ary) To UBound(Ary)
If Trim(Ary(i)) <> "empty" Then ''' trim is use to remove space
Ary_cln(i) = Ary(i) '''input non black values in the clean array
End If
Next i
MsgBox UBound(Ary_cln)
For i = LBound(Ary_cln) to UBound(Ary_cln)
msg = msg & "index " & i & "--" & Ary_cln(i) & Chr(10)
Next i
MsgBox msg, 0, "Array Items"
End Sub
but when I run the code the Ary_cln is equal to Ary with “empty” replaced with “”. refer following snapshot
Please help me in this regards.
Yours Sincerely
Muhammad Ali



