Macro de ordenamiento funciona en ocasiones
Con el gusto de saludarlos y preguntarles, si existe alguna otra forma de hacer funcionar bien una macro.
Estoy realizando un filtro de orden personalizado en una Hoja que esta ligado a una segmentación de datos, donde me filtra por vendedor. Pero al realizar varios filtros con diferentes vendedores llega un punto donde ya no me ordena los datos. Me tengo que meter directamente a Ordenar -> orden personalizado y realizar la actualización de manera manual. El rango es variable, solo ordena por 2 columnas, de manera ascendente, columnaB= numero de registro, columnaA= nombre del producto.
Para esta macro realice 2 códigos diferentes, los cuales si funcionan al principio pero después ya me deja de ordenar.
Anexo macros.
Gracias por sus conocimiento y tiempo.
sub codigo1()
Range("A1:D" & ufil).Select
Selection.Sort Key1:=Range("b2"), Order1:=xlAscending, Key2:=Range("a2") _
, Order2:=xlAscending, Header:= _
xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
End sub
sub codigo2()
Sheets("Hoja3").Select
'ufil = ActiveCell.SpecialCells(xlLastCell).Row
ufil = Range("b1").End(xlDown).Row
ucol = ActiveCell.SpecialCells(xlLastCell).Column
Range(Cells(1, 1), Cells(ufil, ucol)).Select
ActiveWorkbook.Worksheets("Hoja3").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja3").Sort.SortFields.Add _
Key:=Range("B2:B" & ufil), _
SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Hoja3").Sort.SortFields.Add _
Key:=Range("A2:A" & ufil), _
SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Hoja3").Sort
.SetRange Range(Cells(1, 1), Cells(ufil, ucol))
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
end sub