Removes the Duplicate in a single Cell

lancerj017

Active Member
Joined
Jan 25, 2012
Messages
318
hi i have a question for you guys is it possible to remove duplicates the data in a single cell using macro?

Example

Column A
with apple, with banana, with apple, with banana
with apple, with apple, with apple
with banana, with banana, with banana

Need to do:

Column A
with apple, with banana
with apple
with banana

that's data is example only!
 
lancerj017, mirabeau, Biz,


Sample raw data (with each cell of data containing a trailing space character):


Excel Workbook
A
1with apple, with banana, with apple, with banana
2with apple, with apple, with apple
3with banana, with banana, with banana
4with banana
5
6with apple, with banana, with apple, with banana
7with apple, with apple, with apple
8with banana, with banana, with banana
9with apple, with banana, with apple, with banana
10with apple, with apple, with apple
11with banana, with banana, with banana
12with banana
13
14with apple, with banana, with apple, with banana
15with apple, with apple, with apple
16with banana, with banana, with banana
17with apple, with banana, with apple, with banana
18with apple, with apple, with apple
19with banana, with banana, with banana
20with banana
21
22with apple, with banana, with apple, with banana
23with apple, with apple, with apple
24with banana, with banana, with banana
25with apple, with banana, with apple, with banana
26with apple, with apple, with apple
27with banana, with banana, with banana
28with banana
29
Sheet1





Results from:


RemoveDupesV3, in 0.9375 seconds.
qwerty(), with "d.comparemode = vbTextCompare", in 0.3125 seconds.



Excel Workbook
A
1with apple, with banana
2with apple
3with banana
4with banana
5
6with apple, with banana
7with apple
8with banana
9with apple, with banana
10with apple
11with banana
12with banana
13
14with apple, with banana
15with apple
16with banana
17with apple, with banana
18with apple
19with banana
20with banana
21
22with apple, with banana
23with apple
24with banana
25with apple, with banana
26with apple
27with banana
28with banana
29
Sheet1





And, results from asdfgh(), in 0.015625 seconds:


Excel Workbook
AB
1with apple, with banana, with apple, with bananawith apple, with banana, with apple, with banana
2with apple, with apple, with applewith apple
3with banana, with banana, with bananawith banana
4with bananawith banana
5
6with apple, with banana, with apple, with bananawith apple, with banana, with apple, with banana
7with apple, with apple, with applewith apple
8with banana, with banana, with bananawith banana
9with apple, with banana, with apple, with bananawith apple, with banana, with apple, with banana
10with apple, with apple, with applewith apple
11with banana, with banana, with bananawith banana
12with bananawith banana
13
14with apple, with banana, with apple, with bananawith apple, with banana, with apple, with banana
15with apple, with apple, with applewith apple
16with banana, with banana, with bananawith banana
17with apple, with banana, with apple, with bananawith apple, with banana, with apple, with banana
18with apple, with apple, with applewith apple
19with banana, with banana, with bananawith banana
20with bananawith banana
21
22with apple, with banana, with apple, with bananawith apple, with banana, with apple, with banana
23with apple, with apple, with applewith apple
24with banana, with banana, with bananawith banana
25with apple, with banana, with apple, with bananawith apple, with banana, with apple, with banana
26with apple, with apple, with applewith apple
27with banana, with banana, with bananawith banana
28with bananawith banana
29
Sheet1
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Rich (BB code):
 ...
...
a = Trim(Cells(i, 1)) & ","
...
and could you recheck your times for the scripting dictionary approaches?
they often seem slow on the first run
 
Upvote 0
wow all of you are good in vb... can you give me a sample of tutorials? so i can learn your techniques? hays i wish i could learn that vb someday... i can read the code but not totally i can create macro i just know how to understand it...
 
Upvote 0
@miribeau + whomever

your second code identifies symmetric strings and splits them in half, but it obviously does not remove non symmetric strings that contain duplicates.

i have not gone over each previous post, but is it assumed then that the strings will be symmetric?

also strings like:

with banana, with banana, with apple, with apple

would also be "wrong"...so i guess your code assumes the strings are all alternating and symmetric is that accurate?
 
Last edited:
Upvote 0
@miribeau + whomever

your second code identifies symmetric strings and splits them in half, but it obviously does not remove non symmetric strings that contain duplicates.

i have not gone over each previous post, but is it assumed then that the strings will be symmetric?

also strings like:



would also be "wrong"...so i guess your code assumes the strings are all alternating and symmetric is that accurate?
Chirp,

(1) The code splits strings in half if relevant, and splits them in less than half when relevant.

(2) The code answers the OP question as asked. Do you consider that it should have done something else?
If you feel the need for analysis of different strings perhaps you can start a new thread on the topic.
 
Upvote 0
i agree that the code will correctly remove duplicates in the supplied test data, and was just confirming that the test data is the only format in which the data would be supplied.

in the rather obvious cases like:


Excel Workbook
AB
1with apple, with apple, with bananawith apple
2with banana, with apple, with applewith banana, with apple, with apple
Sheet2
 
Upvote 0
what's the difference of code of mirabeau And hiker95
Hiker95 code return the exact value and the blank cells treats as BLANK
mirabeau return the exact value too and fastest than hiker95 code... but the problem is the blank cell treats not as BLANK "try to put single quote in a blank cell" thats what happen after i run the code of Mr. mirabeau i don't know what do you call on that but you can try the RemoveDupesV3 Or qwerty() code if you like just to understand what im talking about..
 
Upvote 0

Forum statistics

Threads
1,215,510
Messages
6,125,228
Members
449,216
Latest member
biglake87

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top