ordenar dependiendo de columna

dragonfire33

Board Regular
Joined
Oct 7, 2021
Messages
90
Office Version
  1. 365
Platform
  1. Windows
hola buenos dias , tengo varios datos numericos entre el rango "z1:tw42" y me gustaria hacer lo siguiente:
1. mediante un mensaje decir "que fila desea ordenar" ya que son 42 filas y
2. otro mensaje " en que columna desea colocar los datos"
la idea es que no sea seleccionado
VBA Code:
Sub Transponer_Ordenado()



Dim Seleccion As Range, rang As Range, mat, i As Long
Dim cont As Long, n As Range, vca As Range
Dim fi As Double, co As Double

fi = Application.InputBox("¿Que fila desea ordenar?", "Fila ordenar", , , , , , 1)
irco:
co = Application.InputBox("¿En que columna desea mostrar?", "Columna ordenar", , , , , , 1)

If fi = 0 Or co = 0 Then Exit Sub

If co > 25 Then GoTo irco:

Set Seleccion = Range("Z" & fi & ":TW" & fi)

Application.ScreenUpdating = False

On Error GoTo error1:

Set rang = Seleccion.SpecialCells(2, 1)
cont = rang.Count

If cont > 1 Then

    'On Error Resume Next
    Columns(co).ClearContents
    'On Error GoTo 0
    
    ReDim mat(1 To cont)
    
    For Each n In rang
        i = i + 1: mat(i) = n
    Next
    
    Cells(2, co).Resize(cont) = Application.Transpose(mat)
    With Cells(1, co)
        .Value = "Num"
        .Sort .Cells, 1, , , , , , 1
        .EntireColumn.AutoFit
    End With
    
    rang.Select
    
    Application.ScreenUpdating = True
    
    VBA.MsgBox "Total valores ordenados: " & cont, vbInformation, "Ordenados"
    
    GoTo ir:
Else
    GoTo ira:
End If

ira:
VBA.MsgBox "Debe seleccionar mas valores", vbCritical, "Seleccion"

ir:
Set rang = Nothing: Set Seleccion = Nothing
Exit Sub

error1:
VBA.MsgBox Err.Description, vbCritical, "GP"

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Prueba esto:

VBA Code:
Sub Transponer_Ordenado()
  Dim fi As Long, co As Long
  
  With Application
    .ScreenUpdating = False
    fi = .InputBox("¿Que fila desea ordenar?", "Fila ordenar", , , , , , 1)
irco:
    co = .InputBox("¿En que columna desea mostrar?", "Columna ordenar", , , , , , 1)
    If fi = 0 Or co = 0 Then Exit Sub
    If co > 25 Then GoTo irco:
    Columns(co).ClearContents
  End With
  
  On Error GoTo error1:
  With Range("Z" & fi & ":TW" & fi).SpecialCells(xlCellTypeConstants, 1)
    If .Count > 0 Then
      .Copy
      With Cells(1, co)
        .Offset(1).PasteSpecial xlPasteValues, , , True
        .Value = "Num"
        Range(.Address, Cells(Rows.Count, co).End(3)).Sort .Cells(1), 1, , , , , , 1
        .EntireColumn.AutoFit
      End With
    End If
  End With
  
  Exit Sub
error1:
  VBA.MsgBox Err.Description, vbCritical, "GP"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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