Saltar al contenido principal

¿Cómo ordenar varias filas o columnas de forma independiente a la vez en Excel?

En Excel, puede aplicar la función Ordenar para ordenar solo una fila o columna en un rango de columnas, pero, si necesita ordenar varias filas o columnas de forma independiente a la vez, se muestra la siguiente captura de pantalla. ¿Hay alguna forma rápida de resolver esta tarea en Excel?

doc ordenar varias columnas 1

Ordene varias columnas de forma independiente a la vez con el código VBA

Ordene varias filas de forma independiente a la vez con el código VBA


flecha azul burbuja derecha Ordene varias columnas de forma independiente a la vez con el código VBA

Para ordenar varias columnas de forma independiente en orden ascendente, el siguiente código VBA puede ayudarlo, haga lo siguiente:

1. Mantenga pulsado el ALT + F11 teclas para abrir el Microsoft Visual Basic para aplicaciones ventana.

2. Hacer clic recuadro > Móduloy pegue el siguiente código en el Módulo Ventana.

Código de VBA: ordena varias columnas de forma independiente a la vez:

Sub SortIndividualJR()
'Updateby Extendoffice
    Dim xRg As Range
    Dim yRg As Range
    Dim ws As Worksheet
    Set ws = ActiveSheet
    On Error Resume Next
    Set xRg = Application.InputBox(Prompt:="Range Selection:", _
                                    Title:="Kutools for excel", Type:=8)
    Application.ScreenUpdating = False
    For Each yRg In xRg
        With ws.Sort
            .SortFields.Clear
            .SortFields.Add Key:=yRg, Order:=xlAscending
            .SetRange ws.Range(yRg, yRg.End(xlDown))
            .Header = xlNo
            .MatchCase = False
            .Apply
        End With
    Next yRg
    Application.ScreenUpdating = True
End Sub

3. Entonces presione F5 para ejecutar este código, y aparece un cuadro emergente para recordarle que seleccione el rango de datos que desea ordenar en función de cada columna, vea la captura de pantalla:

doc ordenar varias columnas 2

4. Y luego haz clic OK, cada columna se ha ordenado de forma dependiente a la vez, vea la captura de pantalla:

doc ordenar varias columnas 1


flecha azul burbuja derecha Ordene varias filas de forma independiente a la vez con el código VBA

Si desea ordenar varias filas de forma independiente, aquí también hay un código VBA para usted.

1. Seleccione los datos que desea ordenar en función de cada fila.

doc ordenar varias columnas 3

2. Mantenga pulsado el ALT + F11 teclas para abrir el Microsoft Visual Basic para aplicaciones ventana.

3. Hacer clic recuadro > Móduloy pegue el siguiente código en el Módulo Ventana.

Código de VBA: ordena varias filas de forma independiente a la vez:

Sub SortIndividualR()
'Updateby Extendoffice
    Dim xRg As Range, yRg As Range
    If TypeName(Selection) <> "Range" Then Exit Sub
    Set xRg = Selection
    If xRg.Count = 1 Then
        MsgBox "Select multiple cells!", vbExclamation, "Kutools for Excel"
        Exit Sub
    End If
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    Application.ScreenUpdating = False
    For Each yRg In xRg.Rows
        yRg.Sort Key1:=yRg.Cells(1, 1), _
        Order1:=xlAscending, _
        Header:=xlNo, _
        Orientation:=xlSortRows
    Next yRg
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
    End With
    Application.ScreenUpdating = True
End Sub

4. Entonces presione F5 clave para ejecutar este código, los datos en cada fila se han ordenado a la vez, vea la captura de pantalla:

doc ordenar varias columnas 4

Las mejores herramientas de productividad de oficina

🤖 Asistente de IA de Kutools: Revolucionar el análisis de datos basado en: Ejecución inteligente   |  Generar codigo  |  Crear fórmulas personalizadas  |  Analizar datos y generar gráficos  |  Invocar funciones de Kutools...
Características populares: Buscar, resaltar o identificar duplicados   |  Eliminar filas en blanco   |  Combine columnas o celdas sin perder datos   |   Ronda sin fórmula ...
Super búsqueda: Búsqueda virtual de criterios múltiples    Búsqueda V de valores múltiples  |   VLookup en varias hojas   |   Búsqueda difusa ....
Lista desplegable avanzada: Crear rápidamente una lista desplegable   |  Lista desplegable dependiente   |  Lista desplegable de selección múltiple ....
Administrador de columnas: Agregar un número específico de columnas  |  Mover columnas  |  Toggle Estado de visibilidad de columnas ocultas  |  Comparar rangos y columnas ...
Características destacadas: Enfoque de cuadrícula   |  Vista de diseño   |   Gran barra de fórmulas    Administrador de hojas y libros de trabajo   |  Biblioteca de Recursos (Texto automático)   |  Selector de fechas   |  Combinar hojas de trabajo   |  Cifrar/descifrar celdas    Enviar correos electrónicos por lista   |  Súper filtro   |   Filtro especial (filtro negrita/cursiva/tachado...) ...
Los 15 mejores conjuntos de herramientas12 Texto Herramientas (Añadir texto, Quitar caracteres, ...)   |   50+ Tabla Tipos (Diagrama de Gantt, ...)   |   40+ Práctico Fórmulas (Calcular la edad según el cumpleaños, ...)   |   19 Inserción Herramientas (Insertar código QR, Insertar imagen desde la ruta, ...)   |   12 Conversión Herramientas (Números a palabras, Conversión de Moneda, ...)   |   7 Fusionar y dividir Herramientas (Filas combinadas avanzadas, Células partidas, ...)   |   ... y más

Mejore sus habilidades de Excel con Kutools for Excel y experimente la eficiencia como nunca antes. Kutools for Excel ofrece más de 300 funciones avanzadas para aumentar la productividad y ahorrar tiempo.  Haga clic aquí para obtener la función que más necesita...

Descripción


Office Tab lleva la interfaz con pestañas a Office y hace que su trabajo sea mucho más fácil

  • Habilite la edición y lectura con pestañas en Word, Excel, PowerPoint, Publisher, Access, Visio y Project.
  • Abra y cree varios documentos en nuevas pestañas de la misma ventana, en lugar de en nuevas ventanas.
  • ¡Aumenta su productividad en un 50% y reduce cientos de clics del mouse todos los días!
Comments (11)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
My data ranges from 0-100; When I Try to sort multiples rows at once, it starts the data off with the 100s, then sorts the rest numerically least to greatest, putting the 100s at the least side of the range. How can I fix this?
This comment was minimized by the moderator on the site
Update; I've realized it is sorting by the first digit in the number only - How do I get it to sort by the whole number?
This comment was minimized by the moderator on the site
Hi, Devyn,
The code works well in my worksheet. Could you upload your Excel file or data screenshot here? So that, we can help to check where the problem is?
Thank you!
This comment was minimized by the moderator on the site
Спасибо тебе человек!!
This comment was minimized by the moderator on the site
excellent post, thank you very much!
This comment was minimized by the moderator on the site
You have just saved me several headaches with this solution! Thanks a ton!
This comment was minimized by the moderator on the site
Thank you so much for this. It really helped. I would also like to know how to sort by color. I have 26 columns, each having different types of items identified by the font color. I would like to alphabetize all the columns individually but in a specific color order. How do I do this?
This comment was minimized by the moderator on the site
I love this, I'm curious as to the functionality of sorting by color for each column individually. I tried this but it didn't work:


Dim xRg As Range
Dim yRg As Range
Dim ws As Worksheet
Set ws = ActiveSheet
On Error Resume Next
Set xRg = Application.InputBox(Prompt:="Range Selection:", _
Title:="Kutools for excel", Type:=8)
Application.ScreenUpdating = False
For Each yRg In xRg
With ws.Sort
.SortFields.Clear
.SortFields.Add Key:=yRg, _
SortOn:=xlSortOnCellColor, Order:=xlDescending, DataOption:=xlSortNormal
.SetRange ws.Range(yRg, yRg.End(xlDown))
.Header = xlNo
.MatchCase = False
.Apply
End With
Next yRg
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
¿Cómo puedo ordenar por color múltiples filas de forma independiente y que las celdas que no tengan color estén a la derecha?
This comment was minimized by the moderator on the site
When I try to sort the columns it sorts data outside of the sected range! Why is this?
This comment was minimized by the moderator on the site
It works great ! thank you !
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations