Anda di halaman 1dari 3

Ordena una matriz de datos por columna

Call funOrdenarPorColumna("Base MRI", "F", "3")



Public Function funOrdenarPorColumna(nonPesta, col, ini)
'Funcion que ordena por columna la Base MRI
celfin = Sheets(nonPesta).Range(col + "90000").End(xlUp).Row
columna = col & ini & ":" & col & celfin
datos = "A" & ini & ":Z" & celfin
ActiveWorkbook.Worksheets(nonPesta).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(nonPesta).Sort.SortFields.Add Key:=Range(columna),
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets(nonPesta).Sort
.SetRange Range(datos)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Function


'If Sheets(nansheet).Cells(iniAs + 1, 1) = "" Then
' valt = nuevaFila(iniAs + 1, nansheet)
'End If

Public Function nuevaFila(numActual, nomHoja)
'Valida ultima fila
filaNueva = numActual & ":" & numActual
celAnt = "A" & (numActual - 1)
celDes = celAnt & ":" & "A" & numActual
Sheets("Formato").Range("A1:J1").Copy
Sheets(nomHoja).Rows(filaNueva).Insert Shift:=xlDown
Application.CutCopyMode = False
Range(celAnt).AutoFill Destination:=Range(celDes), Type:=xlFillSeries
End Function
Ejemplo de Copia de Datos segn parmetros
Public Function funAs()
ini = 3
iniAs = 35
elemento = 7
nansheet = "MRI As"
Do While MRI.Cells(ini, 2) <> ""
If MRI.Cells(ini, elemento) <> "" Then
If funValidar(nansheet, iniAs, ini) Then '37-10
'Salta a la siguiente celda
iniAs = iniAs + 1
'Inserta la fecha
Sheets(nansheet).Cells(iniAs, 2).Value = MRI.Cells(ini, 6).Value
'Inserta la corrida
Sheets(nansheet).Cells(iniAs, 3).Value = MRI.Cells(ini, 4).Value
'Inserta Analista
Sheets(nansheet).Cells(iniAs, 4).Value = MRI.Cells(ini, 3).Value
End If
'Inserta valor segun el Codigo
Select Case MRI.Cells(ini, 2).Value
Case Sheets(nansheet).Cells(29, 5).Value
Sheets(nansheet).Cells(iniAs, 5).Value = MRI.Cells(ini, elemento).Value
Case Sheets(nansheet).Cells(29, 6).Value
Sheets(nansheet).Cells(iniAs, 6).Value = MRI.Cells(ini, elemento).Value
Case Sheets(nansheet).Cells(29, 7).Value
Sheets(nansheet).Cells(iniAs, 7).Value = MRI.Cells(ini, elemento).Value
Case Sheets(nansheet).Cells(29, 8).Value
Sheets(nansheet).Cells(iniAs, 8).Value = MRI.Cells(ini, elemento).Value
Case Sheets(nansheet).Cells(29, 9).Value
Sheets(nansheet).Cells(iniAs, 9).Value = MRI.Cells(ini, elemento).Value
Case Sheets(nansheet).Cells(29, 10).Value
Sheets(nansheet).Cells(iniAs, 10).Value = MRI.Cells(ini, elemento).Value
End Select
End If
'Salta a la siguiente celda
ini = ini + 1
Loop
End Function
Ejemplo usuando matrices de array
Dim CeldaFinal As Integer
Dim arregloCorrida(400) As Variant
Dim arregloInicio(400) As Variant
Dim arregloFin(400) As Variant
Function BuscarOriginalTCuTFe(codigo, corrida)
Dim originalTCuTFe(2) As String

originalTCuTFe(1) = ""
originalTCuTFe(2) = ""

'Busca la posicion
posicion = Application.Match(corrida, arregloCorrida, False)
Inicio = arregloInicio(posicion - 1)
fin = arregloFin(posicion - 1)

For x = Inicio To fin
If Sheets("Original").Cells(x, 2) = codigo And Sheets("Original").Cells(x, 5) = corrida Then
originalTCuTFe(1) = Sheets("Original").Cells(x, 20)
originalTCuTFe(2) = Sheets("Original").Cells(x, 21)
Exit For
End If
Next
BuscarOriginalTCuTFe = originalTCuTFe

End Function
Function Filas()
'FUNCION que crea rangos de celdas de acuerdo a las corridas Ej. Corrida 454647 FilaInicio 25
FilaFin 79
'Nos sirve para acelerar la busqueda de los originales
Dim indice As Integer
indice = 1
ini = 3
For x = 3 To CeldaFinal
If Sheets("Original").Cells(x, 5).Value <> Sheets("Original").Cells(x + 1, 5).Value Then
arregloInicio(indice) = ini
arregloFin(indice) = x
arregloCorrida(indice) = Sheets("Original").Cells(x, 5).Value
ini = x + 1
indice = indice + 1
End If
Next
'For i = 1 To 240
' Debug.Print i & " - " & arregloCorrida(i) & " - " & arregloInicio(i) & " - " & arregloFin(i)
'Next

End Function

Anda mungkin juga menyukai