I can't find a way to remove duplicate values inside a same cell in Excel. For example, in A1, I have:
DOG DOG DOG
I want to have only DOG.
Actual code:
Sub test()
for i = 14 to 16
transNumb= commRead(i, 23, 4)
next
If transNumb <> " " and transNumb <> "F PA" then
transNumbAcum = transNumbAcum + " " + transNumb
End if
Set exlTest = objExcel.Workbooks.Open(strPathExc)
objExcel.Application.Visible = True
exlTest.Sheets("ACCOUNT_CODE Day").Activate
exlTest.Sheets("ACCOUNT_CODE Day").Cells(37, 4).Value = +transNumbAcum
exlTest.Close xlSaveChanges
objExcel.Quit
End sub
Code output: This will result certain values in the Excel cell (37, 4), such as:
2000 3000 0300 0300 2000
I am lost as to how to delete the repeated values in the cell.
EDIT:
I have these values in my cell A46: 2000 3000 4000 5000 3000 2000
Code I'm trying (doesn't seem to work)
Set d = CreateObject("Scripting.Dictionary")
a = Split(objExcel.Sheets("ACCOUNT_CODE Day").Range("A46"), " ")
For i = 0 To UBound(a)
If Not d.Exists(a(i)) Then d.Add a(i), ""
Next
'Now your Dictionary should have unique values from your cell and you can recombine them:
Set exlTest = objExcel.Workbooks.Open(strPathExc)
objExcel.Application.Visible = True
exlTest.Sheets("ACCOUNT_CODE Day").Activate
'exlTest.Sheets("ACCOUNT_CODE Day").Cells(37, 4).Value = +transNumbAcum
'exlTest.Close xlSaveChanges
'objExcel.Quit
objExcel.Sheets("ACCOUNT_CODE Day").Range("A46") = Join(d.Keys, " ")
exlTest.Close xlSaveChanges
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire