Cut Paste macro required

JAVEDR

Board Regular
Joined
Sep 17, 2019
Messages
79
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
  3. Web
Hello,
Steps below-

1. Required to sort column A, B, C & D
2. After sort Ankur entries in Column B need below Ravi entries in Column B.

Thanks for your suggestion's and reply


1HeaderHeaderHeader1HeaderHeaderHeader
2Data1RAVIAAA2Data1RAVIAAA
3Data2ANKURBBB4Data3RAVIAAA
4Data3RAVIAAA3Data2ANKURBBB
5Data4ANKURBBB5Data4ANKURBBB
6Data5VIVEKCCC6Data5VIVEKCCC
RAW DATAREQUIRED RESULT
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
try something like
VBA Code:
With ActiveSheet
       With .Cells(1, "B").CurrentRegion
.Cells.Sort Key1:=.Range("D1"), Order1:=xlAscending, Key2:=.Range("B1"), Order2:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
       End With
End With
 
Upvote 0
Hi dave thanks for your reply, code is working find on example data but not working on original data,

1693282857658.png
 
Upvote 0
2. After sort Ankur entries in Column B need below Ravi entries in Column B.
From your image it looks like Ankur & Ravi entries are in column C not B. Assuming they are in column C, try this (with a copy of your data) but everything is a bit vague.
Your image in post #3 shows us absolutely nothing of use.

VBA Code:
Sub Sort_Special()
  With Range("A1").CurrentRegion
    .Replace What:="ANKUR", Replacement:="RAVIANKUR", LookAt:=xlWhole
    .Sort Key1:=.Columns(3), Order1:=xlAscending, Header:=xlYes
    .Replace What:="RAVIANKUR", Replacement:="ANKUR", LookAt:=xlWhole
  End With
End Sub

Also, your thread title mentions cut/paste but your description is about sorting. Very confusing! :huh:
 
Upvote 0
From your image it looks like Ankur & Ravi entries are in column C not B. Assuming they are in column C, try this (with a copy of your data) but everything is a bit vague.
Your image in post #3 shows us absolutely nothing of use.

VBA Code:
Sub Sort_Special()
  With Range("A1").CurrentRegion
    .Replace What:="ANKUR", Replacement:="RAVIANKUR", LookAt:=xlWhole
    .Sort Key1:=.Columns(3), Order1:=xlAscending, Header:=xlYes
    .Replace What:="RAVIANKUR", Replacement:="ANKUR", LookAt:=xlWhole
  End With
End Sub

Also, your thread title mentions cut/paste but your description is about sorting. Very confusing! :unsure:
Hello peter, Thank you for your feedback with code

Due to data privacy unable to share whole data hence #3 post agree not of use.
You are correct entries are in column C not in B apologies for confusion again.

Please find below exact I'm looking out

Step1. I have data in Column A to D, which I want to sort from A, then B, then C and then D after that suppose

Step2. Column B if Ravi entries are on top that need to be place below Ankur entries. If no entries found then ignore.

Thank you for valuable time on this
 
Upvote 0
Due to data privacy unable to share whole data
Then what about making up some dummy data that is not private but demonstrates the issues you want to deal with and give us that data with an explanation in relation to the dummy data?
 
Upvote 0
Then what about making up some dummy data that is not private but demonstrates the issues you want to deal with and give us that data with an explanation in relation to the dummy data?
Book9.xlsx

Have shared actual file on Drive. Thank you once again for making me correct
 
Upvote 0
Your request says
I Want Column B DES To Come Below FOA After Sort Of Column A, B, C & D
However there is not enough information about ..
  • What columns are sorted 1st, 2nd, 3rd & 4th
  • Whether column B should basically be sorted ascending or descending. For example, why is "Interactive" below "Samlyn Capital"?
 
Upvote 0
Your request says

However there is not enough information about ..
  • What columns are sorted 1st, 2nd, 3rd & 4th
  • Whether column B should basically be sorted ascending or descending. For example, why is "Interactive" below "Samlyn Capital"?
Yes peter,

First sort Column as ascending (atoz) requested Column A, then B, then C & then D
Once sorted **ES to come below *OA
 
Upvote 0
First sort Column as ascending (atoz) requested Column A, then B, then C & then D
If I sort column A ascending, then B ascending then C then D I end up with this.
How can you then just move DES below FOA?
.. and what are you now saying **ES below *OA. Why the change? How does that relate to the sample data?

You also did not address the question of why "Interactive" comes below "Samlyn Capital" if that column is sorted ascending?

EDIT
Data removed at OP's request.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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