merging two data file with same rows in a new columns for new dictionary (macro)

osmanoca

Board Regular
Joined
Apr 16, 2016
Messages
87
Hello dear helpfull mrexcel friends..i need help please. very important .thanks

i have two excel file for dictionary. Both are for two languages . both are with columns. word and meaning. but one language of two dictionaries is same. for example i have English-kurdish and kurdis-persian files. i want make make persian english new dictionary with same rows in kurdish. i pasted their columns side to side as: Eng-Kur is column A and B , Kurdish-Persian column is C and D so i want merging or bringing same rows in kurdish (column B-C) in one row.


example
my Eng-Kurdish data as below:

ENGKU
bookpirtûk
tablemase
treedar

<colgroup><col><col></colgroup><tbody>
</tbody>

my kurdish-Persian data as below:

KURPERS
dardirext
sarserd
pirtûkketab
masemiz
zêrzer
mêrmerd

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>


i pasted two file side by side in one file as ABCD columns as below:

ENGKUKUPERS
bookpirtûkdardirext
tablemasesarserd
treedarpirtûkketab
masemiz
zêrzer
mêrmerd

<colgroup><col><col span="3"></colgroup><tbody>
</tbody>

i want macro code to rearrange and bring only same rows with two columns near to eachother in new columns as below:

ENGKUKUPERS
bookpirtûkpirtûkketab
tablemasemasemiz
treedardardirext

<colgroup><col><col span="3"></colgroup><tbody>
</tbody>

then i will delete kurdish columns and make ENG-PERS dictionary

please give me a way to arrive this solution. macro please. very very thanks..
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi, osmanoca
Question:
Is it possible that value in col B has no match in col C? Say there is ‘pirtûk’ in col B but not in col C.
Are there any duplicates in any column? Say ‘tree’ & ‘lemon’ is ‘dar’ in Kurdish Sorry, I don’t know the real example to show my point. I modified your sample data, something like this:

Excel 2007 32 bit
A
B
C
D
1
ENGKUKUPERS
2
bookpirtûkdardirext
3
tablemasesarserd
4
treedarmasemiz
5
lemondarzêrzer
6
mêrmerd

<tbody>
</tbody>
Sheet: Sheet5

<tbody>
</tbody>
 
Last edited:
Upvote 0
Thanks for answer. They are two different dictionary database. So columns AB are data of a dict. and CD are another dict data. So of course many words will be different between B and C. But i want only to bring same rows of B and C to same row. Others are different and i dont want them. İf i can bring B and C with their words in same rows in one new row, then i will create new dict from their rows words.
İf B and C is same i want macro to take them with A and D into new row.

Hi, osmanoca



Question:
Is it possible that value in col B has no match in col C? Say there is ‘pirtûk’ in col B but not in col C.
Are there any duplicates in any column? Say ‘tree’ & ‘lemon’ is ‘dar’ in Kurdish Sorry, I don’t know the real example to show my point. I modified your sample data, something like this:

Excel 2007 32 bit
A
B
C
D
1
ENGKUKUPERS
2
bookpirtûkdardirext
3
tablemasesarserd
4
treedarmasemiz
5
lemondarzêrzer
6
mêrmerd

<tbody>
</tbody>
Sheet: Sheet5

<tbody>
</tbody>
 
Last edited:
Upvote 0
Ok, that answered my first question, which is ‘yes’.
But what about duplicate? Is there any duplicate?
 
Upvote 0
Only in B or C no dublicated. But may be. İf possible you can give two codes. İf there is dublicated it can merge also.
 
Upvote 0
Ok, try this.
But it doesn’t deal with the duplicates problem yet, but see how it works.
I’m using col E as helper column. The result that you want is the ones with ‘1’ in col E.



Please use Code Tags when posting a code. Like this: [CODE ]Your Code Here[/ CODE]
Code:
[B][COLOR=Royalblue]Sub[/COLOR][/B] a1018125a[B]()[/B]
[B][COLOR=Royalblue]Dim[/COLOR][/B] i [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B][B],[/B] va[B],[/B] vc[B],[/B] vd
[B][COLOR=Royalblue]Dim[/COLOR][/B] d [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Object[/COLOR][/B]
 
    Range[B]([/B][B][COLOR=brown]"A:B"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"B1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
    Range[B]([/B][B][COLOR=brown]"C:D"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"C1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
   
    [B][COLOR=Royalblue]Set[/COLOR][/B] d [B]=[/B] CreateObject[B]([/B][B][COLOR=brown]"scripting.dictionary"[/COLOR][/B][B])[/B]
        d.CompareMode [B]=[/B] vbTextCompare [FONT=trebuchet ms][I][COLOR=Lightseagreen]'vbBinaryCompare[/COLOR][/I][/FONT]
            va [B]=[/B] Range[B]([/B][B][COLOR=brown]"B2"[/COLOR][/B][B],[/B] Cells[B]([/B]Rows.count[B],[/B] [B][COLOR=brown]"B"[/COLOR][/B][B]).[/B][B][COLOR=Royalblue]End[/COLOR][/B][B]([/B]xlUp[B]))[/B]
                vc [B]=[/B] Range[B]([/B][B][COLOR=brown]"C2"[/COLOR][/B][B],[/B] Cells[B]([/B]Rows.count[B],[/B] [B][COLOR=brown]"C"[/COLOR][/B][B]).[/B][B][COLOR=Royalblue]End[/COLOR][/B][B]([/B]xlUp[B]))[/B]
                    [B][COLOR=Royalblue]ReDim[/COLOR][/B] vd[B]([/B][B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]vc[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]),[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]vc[B],[/B] [B][B][COLOR=crimson]2[/COLOR][/B][/B][B]))[/B]
 
    [B][COLOR=Royalblue]For[/COLOR][/B] i [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]va[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
        d[B]([/B]va[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B] [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
   
    [B][COLOR=Royalblue]For[/COLOR][/B] i [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]vc[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
        [B][COLOR=Royalblue]If[/COLOR][/B] d.exists[B]([/B]vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B] [B][COLOR=Royalblue]Then[/COLOR][/B]
            vd[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B] [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B]
            d[B]([/B]vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B] [B]=[/B] [B][B][COLOR=crimson]2[/COLOR][/B][/B]
        [B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]If[/COLOR][/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
   
    [B][COLOR=Royalblue]For[/COLOR][/B] i [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]va[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
       [B][COLOR=Royalblue]If[/COLOR][/B] d[B]([/B]va[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B] [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]Then[/COLOR][/B] va[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B] [B]=[/B] [B][COLOR=brown]""[/COLOR][/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
   
    Range[B]([/B][B][COLOR=brown]"B2"[/COLOR][/B][B]).[/B]Resize[B]([/B]UBound[B]([/B]va[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]),[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B] [B]=[/B] va
    Range[B]([/B][B][COLOR=brown]"E2"[/COLOR][/B][B]).[/B]Resize[B]([/B]UBound[B]([/B]vd[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]),[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B] [B]=[/B] vd
  
    Range[B]([/B][B][COLOR=brown]"A:E"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"E1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
    Range[B]([/B][B][COLOR=brown]"A:B"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"B1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
 
 
[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]

 
Upvote 0
Using your sample above, here's the result:


Excel 2007 32 bit
A
B
C
D
E
1
ENGKUKUPERS
2
treedardardirext
1​
3
tablemasemasemiz
1​
4
bookpirtûkpirtûkketab
1​
5
mêrmerd
6
sarserd
7
zêrzer

<tbody>
</tbody>
Sheet: Sheet9

<tbody>
</tbody>
 
Upvote 0
I wrote another macro, I think it is more reliable than the one I gave you above. Try it. It will insert the English words in col E, that’s the result you want.


Please use Code Tags when posting a code. Like this: [CODE ]Your Code Here[/ CODE]
Code:
[B][COLOR=Royalblue]Sub[/COLOR][/B] a1018125b[B]()[/B]
[B][COLOR=Royalblue]Dim[/COLOR][/B] i [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B][B],[/B] va[B],[/B] vc
[B][COLOR=Royalblue]Dim[/COLOR][/B] d [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Object[/COLOR][/B]
 
   
    [B][COLOR=Royalblue]Set[/COLOR][/B] d [B]=[/B] CreateObject[B]([/B][B][COLOR=brown]"scripting.dictionary"[/COLOR][/B][B])[/B]
        d.CompareMode [B]=[/B] vbTextCompare [FONT=trebuchet ms][I][COLOR=Lightseagreen]'vbBinaryCompare[/COLOR][/I][/FONT]
            va [B]=[/B] Range[B]([/B][B][COLOR=brown]"A2"[/COLOR][/B][B],[/B] Cells[B]([/B]Rows.count[B],[/B] [B][COLOR=brown]"B"[/COLOR][/B][B]).[/B][B][COLOR=Royalblue]End[/COLOR][/B][B]([/B]xlUp[B]))[/B]
                vc [B]=[/B] Range[B]([/B][B][COLOR=brown]"C2:E"[/COLOR][/B] [B]&[/B] Cells[B]([/B]Rows.count[B],[/B] [B][COLOR=brown]"D"[/COLOR][/B][B]).[/B][B][COLOR=Royalblue]End[/COLOR][/B][B]([/B]xlUp[B]).[/B]row[B])[/B]
 
    [B][COLOR=Royalblue]For[/COLOR][/B] i [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]va[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
        d[B]([/B]va[B]([/B]i[B],[/B] [B][B][COLOR=crimson]2[/COLOR][/B][/B][B]))[/B] [B]=[/B] va[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
   
    [B][COLOR=Royalblue]For[/COLOR][/B] i [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]vc[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
        [B][COLOR=Royalblue]If[/COLOR][/B] d.exists[B]([/B]vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B] [B][COLOR=Royalblue]Then[/COLOR][/B]
            vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]3[/COLOR][/B][/B][B])[/B] [B]=[/B] d[B]([/B]vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B]
        [B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]If[/COLOR][/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
   
    Range[B]([/B][B][COLOR=brown]"C2"[/COLOR][/B][B]).[/B]Resize[B]([/B]UBound[B]([/B]vc[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]),[/B] [B][B][COLOR=crimson]3[/COLOR][/B][/B][B])[/B] [B]=[/B] vc
    Range[B]([/B][B][COLOR=brown]"C:E"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"E1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
    Range[B]([/B][B][COLOR=brown]"A:B"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"A1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
 
[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]


Excel 2007 32 bit
A
B
C
D
E
1
ENGKUKUPERS
2
bookpirtûkpirtûkketabbook
3
tablemasemasemiztable
4
treedardardirexttree
5
sarserd
6
zêrzer
7
mêrmerd

<tbody>
</tbody>
Sheet: Sheet2

<tbody>
</tbody>
 
Upvote 0
thnaks Akuini . code worked well. but the problem is in dublicated rows as you said. so before this code i have to merge dublicated in b and c and then run the code. it will be fine so. thanks.

I wrote another macro, I think it is more reliable than the one I gave you above. Try it. It will insert the English words in col E, that’s the result you want.


Please use Code Tags when posting a code. Like this: [CODE ]Your Code Here[/ CODE]
Code:
[B][COLOR=Royalblue]Sub[/COLOR][/B] a1018125b[B]()[/B]
[B][COLOR=Royalblue]Dim[/COLOR][/B] i [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Long[/COLOR][/B][B],[/B] va[B],[/B] vc
[B][COLOR=Royalblue]Dim[/COLOR][/B] d [B][COLOR=Royalblue]As[/COLOR][/B] [B][COLOR=Royalblue]Object[/COLOR][/B]
 
   
    [B][COLOR=Royalblue]Set[/COLOR][/B] d [B]=[/B] CreateObject[B]([/B][B][COLOR=brown]"scripting.dictionary"[/COLOR][/B][B])[/B]
        d.CompareMode [B]=[/B] vbTextCompare [FONT=trebuchet ms][I][COLOR=Lightseagreen]'vbBinaryCompare[/COLOR][/I][/FONT]
            va [B]=[/B] Range[B]([/B][B][COLOR=brown]"A2"[/COLOR][/B][B],[/B] Cells[B]([/B]Rows.count[B],[/B] [B][COLOR=brown]"B"[/COLOR][/B][B]).[/B][B][COLOR=Royalblue]End[/COLOR][/B][B]([/B]xlUp[B]))[/B]
                vc [B]=[/B] Range[B]([/B][B][COLOR=brown]"C2:E"[/COLOR][/B] [B]&[/B] Cells[B]([/B]Rows.count[B],[/B] [B][COLOR=brown]"D"[/COLOR][/B][B]).[/B][B][COLOR=Royalblue]End[/COLOR][/B][B]([/B]xlUp[B]).[/B]row[B])[/B]
 
    [B][COLOR=Royalblue]For[/COLOR][/B] i [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]va[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
        d[B]([/B]va[B]([/B]i[B],[/B] [B][B][COLOR=crimson]2[/COLOR][/B][/B][B]))[/B] [B]=[/B] va[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
   
    [B][COLOR=Royalblue]For[/COLOR][/B] i [B]=[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B] [B][COLOR=Royalblue]To[/COLOR][/B] UBound[B]([/B]vc[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B])[/B]
        [B][COLOR=Royalblue]If[/COLOR][/B] d.exists[B]([/B]vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B] [B][COLOR=Royalblue]Then[/COLOR][/B]
            vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]3[/COLOR][/B][/B][B])[/B] [B]=[/B] d[B]([/B]vc[B]([/B]i[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]))[/B]
        [B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]If[/COLOR][/B]
    [B][COLOR=Royalblue]Next[/COLOR][/B]
   
    Range[B]([/B][B][COLOR=brown]"C2"[/COLOR][/B][B]).[/B]Resize[B]([/B]UBound[B]([/B]vc[B],[/B] [B][B][COLOR=crimson]1[/COLOR][/B][/B][B]),[/B] [B][B][COLOR=crimson]3[/COLOR][/B][/B][B])[/B] [B]=[/B] vc
    Range[B]([/B][B][COLOR=brown]"C:E"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"E1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
    Range[B]([/B][B][COLOR=brown]"A:B"[/COLOR][/B][B]).[/B]Sort Key1[B]:=[/B]Range[B]([/B][B][COLOR=brown]"A1"[/COLOR][/B][B]),[/B] Order1[B]:=[/B]xlAscending[B],[/B] Header[B]:=[/B]xlYes
 
[B][COLOR=Royalblue]End[/COLOR][/B] [B][COLOR=Royalblue]Sub[/COLOR][/B]


Excel 2007 32 bit
A
B
C
D
E
1
ENGKUKUPERS
2
bookpirtûkpirtûkketabbook
3
tablemasemasemiztable
4
treedardardirexttree
5
sarserd
6
zêrzer
7
mêrmerd

<tbody>
</tbody>
Sheet: Sheet2

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,294
Members
449,149
Latest member
mwdbActuary

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