Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Old November 22nd 20, 10:03 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Oct 2018
Posts: 4
Default Eliminate duplicate words from string

If I have a string of words, such as:

sWords = "person person woman man camera TV TV person man man"

What is an efficient way to remove duplicate words? The variable sWords should contain "person woman man camera TV".

Thanks!

  #2   Report Post  
Old November 22nd 20, 10:25 AM posted to microsoft.public.excel.programming
external usenet poster
 
First recorded activity by ExcelBanter: Apr 2011
Posts: 3,813
Default Eliminate duplicate words from string

Hi,

Am Sun, 22 Nov 2020 01:03:30 -0800 (PST) schrieb Tatsujin:

If I have a string of words, such as:

sWords = "person person woman man camera TV TV person man man"

What is an efficient way to remove duplicate words? The variable sWords should contain "person woman man camera TV".


try:

Sub Test()
Dim sWords As String
Dim myDic As Object
Dim varWords As Variant, varTmp As Variant
Dim i As Integer

sWords = "person person woman man camera TV TV person man man"
varWords = Split(sWords, " ")
Set myDic = CreateObject("scripting.dictionary")
For i = LBound(varWords) To UBound(varWords)
myDic(varWords(i)) = varWords(i)
Next i
varTmp = myDic.items
sWords = Join(varTmp, " ")
End Sub


Regards
Claus B.
--
Windows10
Office 2016


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Eliminate Duplicate Row Chip Excel Discussion (Misc queries) 1 September 25th 09 09:18 PM
how to eliminate duplicate numbers OPer Excel Worksheet Functions 5 September 11th 09 10:29 PM
Create a macro to eliminate certain words from several columns Jorge Excel Worksheet Functions 4 January 16th 08 09:15 PM
How to eliminate duplicate entries Tara Keane Excel Discussion (Misc queries) 4 March 2nd 05 06:33 PM
macro to eliminate spaces between words CSAM Excel Discussion (Misc queries) 3 December 17th 04 12:39 PM


All times are GMT +1. The time now is 10:27 PM.

Powered by vBulletin® Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright 2004-2020 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"

 

Copyright © 2017