bring same rows side by side - please help macro

osmanoca

Board Regular
Joined
Apr 16, 2016
Messages
87
hello please help
i have 4 columns and there words in them. i want a code to bring same rows in column C with B to side bye side same row with moving C and D rows together. so i want to see same words in C next to same words in B but code must move C words with its meaning in D. others that not same can be deleted or can be in bottom.
example:
A - B - C - D
baş - good - eye - çav
xirab - bad - friend - hogir
çav - eye - good - rind
heval - friend - eat - xwarin

i want them in result.

A - B - C - D
baş - good - good - rind
çav - eye - eye - çav
heval - friend - friend - hogir


please help with macro
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub AlignWordsBasedOnColumnsBandC()
  Dim X As Long, Z As Long, Arr As Variant, Words As Variant, Result As Variant
  Application.ScreenUpdating = False
  With Range("C1", Cells(Rows.Count, "D").End(xlUp))
    Arr = .Value
    ReDim Result(1 To UBound(Arr), 1 To 2)
    Words = Application.Transpose(.Columns.Offset(, -1).Resize(, 1))
    .ClearContents
    For X = 1 To UBound(Words)
      For Z = 1 To UBound(Arr)
        If Words(X) = Arr(Z, 1) Then
          Result(X, 1) = Arr(Z, 1)
          Result(X, 2) = Arr(Z, 2)
          Exit For
        End If
      Next
    Next
    .Value = Result
    On Error GoTo NoBlanks
    Intersect(.Resize(, 1).SpecialCells(xlBlanks).EntireRow, Columns("A:D")).Delete xlShiftUp
  End With
NoBlanks:
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
this code works good but it doesnt make all words. i see that there are many words that same in both columns but it didnt take to new arrange.

so there is a small problem .
 
Upvote 0
this code works good but it doesnt make all words. i see that there are many words that same in both columns but it didnt take to new arrange.
Are the words all the same casing? Are they spelled exactly the same? Actually, I would be willing to bet that if you check, you will find one of the pair of words has one or more trailing blanks in it. If I am right about the trailing space, then this modified code should work (it will also handle different letter casing as well)...
Code:
[table="width: 500"]
[tr]
	[td]Sub AlignWordsBasedOnColumnsBandC()
  Dim X As Long, Z As Long, Arr As Variant, Words As Variant, Result As Variant
  Application.ScreenUpdating = False
  With Range("C1", Cells(Rows.Count, "D").End(xlUp))
    Arr = .Value
    ReDim Result(1 To UBound(Arr), 1 To 2)
    Words = Application.Transpose(.Columns.Offset(, -1).Resize(, 1))
    .ClearContents
    For X = 1 To UBound(Words)
      For Z = 1 To UBound(Arr)
        If UCase(Trim(Words(X))) = UCase(Trim(Arr(Z, 1))) Then
          Result(X, 1) = Trim(Arr(Z, 1))
          Result(X, 2) = Trim(Arr(Z, 2))
          Exit For
        End If
      Next
    Next
    .Value = Result
    On Error GoTo NoBlanks
    Intersect(.Resize(, 1).SpecialCells(xlBlanks).EntireRow, Columns("A:D")).Delete xlShiftUp
  End With
NoBlanks:
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
yes thanks i thought like you, perhaps case and spaces make problem. i wll check and return. thanks really.
 
Upvote 0
thank you dear sir and firends. it worked good. the god help you in your life as you helped me.

see you thanks very much all.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,614
Members
449,091
Latest member
gaurav_7829

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