0
votes

So i have Columns C tru J with data:

Last Names | first Name | Phone ... etc

Im trying to sort at the end of a macro the whole Column C by Last Names alphabetically, Starting from C14 to C9999

i have this, have tried other codes but keep getting the same error:

Range("C14").CurrentRegion.Sort [C14], xlAscending

the All merged cells must be the same size keeps showing up, idk why, i have checked and i dont have any mergeded cells!!!

Please help.

1
If it says there are merged cells then there are. Check again. Also see Detect merged cells in VBA Excel with MergeArea and 2 Practical Methods to Find Merged Cells in Your Excel how to find them. - Pᴇʜ
it returns ? Activecell.Mergecells False ? Activecell.MergeArea.Columns.Count 1 ? Activecell.MergeArea.Rows.Count 1 - Javy Colón
Using Method #2 We couldn't find what you were looking for. click options for more ways to search. :/ - Javy Colón

1 Answers

0
votes

Your Range object has no worksheet specified. Therefore Excel is not using the worsheet you think it uses. So actually Excel tries to sort on a wrong worksheet and that has merged cells.

Never use Range without specifying the worksheet:

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1") 'specify your name

ws.Range("C14").CurrentRegion.Sort ws.Range("C14"), xlAscending

Also instead of [C14] use a proper referenece with worksheet ws.Range("C14").


Edit according comment:

To sort only from C14 downwards use:

With ws.Range("C14").CurrentRegion
    .Resize(RowSize:=.Rows.Count - 14 + .Row - 1).Offset(RowOffset:=14 - .Row + 1).Sort ws.Range("C14"), xlAscending
End With