Posibilidad de Mejorar macro existente
Me ayudaste con la siguiente macro.
Private Sub Worksheet_Change(ByVal Target As Range)
'Por.Dante Amor
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C7")) Is Nothing Then
If Target = "" Then Exit Sub
Set h1 = Sheets("CARTERA")
u = h1.Range("A" & Rows.Count).End(xlUp).Row
With h1.Sort
.SortFields.Clear
.SortFields.Add Key:=h1.Range("C3:C" & u)
.SortFields.Add Key:=h1.Range("A3:A" & u)
.SetRange Range("A2:E" & u): .Header = xlYes: .Apply
End With
'
n = 0
cad = ""
Set r = h1.Columns("C")
Set b = r.Find(Target, lookat:=xlWhole, SearchDirection:=xlPrevious)
If Not b Is Nothing Then
ncell = b.Address
cliente = h1.Cells(b.Row, "D")
Do
'detalle
n = n + 1
If n < 4 Then
cad = cad & h1.Cells(b.Row, "A") & " - " & h1.Cells(b.Row, "E") & vbCr
Else
Exit Do
End If
Set b = r.FindPrevious(b)
Loop While Not b Is Nothing And b.Address <> ncell
End If
'
If cad = "" Then
MsgBox "Dicho cliente es nuevo y aún no ha comprado en nuestra tienda", vbExclamation, "CLIENTE: " & Target
Else
MsgBox cad, , "Últimas compras del Cliente: " & Target & " - " & cliente
End If
Target.Select
End If
End SubAl principio pensé que era lo que necesitaba, pero lastimosamente poniendola en ejecución me di cuenta que la macro organiza los datos de la hoja "Cartera" por "Id Cliente" y como segunda prioridad por "Fecha" y lastimosamente en mi caso particular, no me sirve que los datos que están en la hoja "cartera" sean organizados por que me causa conflictos con otras estadisticas que manejo. Por lo tanto te qusiera preguntar, si hay la posibilidad de lograr el mismo objetivo pero sin ordenar los datos de la hoja "cartera"
1 Respuesta
Respuesta de Dante Amor
1