Sort is not sorting all data in the same row....Really!

CastingDirector

New Member
Joined
Jun 10, 2014
Messages
46
I would be so grateful for any/all help.
So here is the data BEFORE the sort macro (note actor A has corresponding notes in the same row (e)):
NAA10/02/15 Actor DCarol|Notes on Actor D
NAA10/02/15 Actor ETed|Notes on Actor E
NAA10/02/15 Actor FTed|Notes on Actor F
NAA10/02/15 Actor GBob|No Notes
NAA10/02/15 Actor HTed|Notes on Actor H
NA10/02/15 Actor CBob|Notes on Actor C
NAA10/02/15 Actor ACarol|Notes on A
PASS10/02/15 Actor BAlice|Notes on B

<tbody>
</tbody>
NOW AFTER THE CODE is processed with the macro:
Alice
NAA10/02/15Actor DNotes on B
Bob
NAA10/02/15Actor ENo Notes
NAA10/02/15Actor FNotes on Actor C
Carol
NAA10/02/15Actor GNotes on A
NAA10/02/15Actor HNotes on Actor D
Ted
NA10/02/15Actor CNotes on Actor E
NAA10/02/15Actor ANotes on Actor F
PASS10/02/15Actor BNotes on Actor H

<tbody>
</tbody>
I am thrilled it works...except....what the?!? The notes in column E do not correspond to the actor?!?

Here is the code...can you see where I've gone wrong? Could really use your help. I promise to give back when I can!
Code:
Option Explicit    Sub CastingDirector()
Dim sh As Worksheet, LR As Long, spl As Variant, i As Long, r As Long
Dim NR As Long
Dim Arange As Range
Dim x As Long
Dim BR As Long
    Set sh = Sheet4
NR = sh.Cells(Rows.Count, "E").End(xlUp).Row
    For r = NR To 6 Step -1
    If InStr(1, sh.Cells(r, 5).Value, "|") > 0 Then
         Set Arange = Range("E6:E" & NR)
         With Arange
         .Sort Key1:=Arange, Order1:=xlAscending, Header:=False
         End With
    End If
    Next
LR = sh.Cells(Rows.Count, "B").End(xlUp).Row
    For i = LR To 6 Step -1
       If sh.Cells(i, 5) Like "*|*" Then
        spl = Split(sh.Cells(i, 5).Value, "|")
        sh.Rows(i).Insert
        sh.Range("B" & i) = Trim(spl(LBound(spl)))
        With sh.Range("B" & i)
        .Font.Bold = True
        .Font.Size = 14
        End With
        sh.Range("E" & i + 1) = Trim(spl(UBound(spl)))
    End If
    Next
    BR = Range("A350").End(xlUp).Row
    For x = BR To 6 Step -1
    If Application.WorksheetFunction.CountIf(Range("B6:B" & x), Range("B" & x).Text) > 1 Then
    Range("A" & x).EntireRow.Delete
    End If
       
    Next x
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,

I can't work out what your code is supposed to do but the error is in here:
Code:
         Set Arange = Range("E6:E" & NR)
         With Arange
         .Sort Key1:=Arange, Order1:=xlAscending, Header:=False
         End With
You need to tell it both the range to sort and the key. Currently, you are telling if to sort the range Arange only.
Unfortunately, there are lots of ways to do this but I will have to pick only one - and I don't know what range you are trying to sort.

Code:
    Range("A6:E" & NR).Sort Key1:=Range("E6"), Order1:=xlAscending, Header:=False
 
Upvote 0

Forum statistics

Threads
1,216,727
Messages
6,132,354
Members
449,720
Latest member
NJOO7

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