Mostrar valores que cumplan con una condición.
Tengo una macro que busca los valores que pertenecen a un mismo código y debe mostrarlos en un ListBox en 3 columnas pero solo me muestra la primera, ya revise el código y no veo el error, no se porque no los muestra todos.
Private Sub BUSCAR_Click()
Application.ScreenUpdating = False
'Busqueda de codigo de la Postevnta
Sheets("CUADRO DE LOCATIVAS").Select
Range("T4").Select
Dim codigo As String
Dim LOC, X1 As Single
COLMTX = 0
Do Until ActiveCell.Offset(0, 0) = ""
If ActiveCell.Offset(0, 0) = Txtpostventas.Text Then
codigo = ActiveCell.Offset(0, -12)
End If
ActiveCell.Offset(1, 0).Select
Loop
lblcodigopost = codigo
Sheets("CUADRO DE LOCATIVAS").Select
'CARGAR MATRIZ DE LOCATIVAS PERTENECIENTES A LA POSTVENTA
Sheets("CUADRO DE LOCATIVAS").Select
Range("H4").Select
'CONTEO LOCATIVAS
Do Until ActiveCell.Offset(0, 0) = ""
If ActiveCell.Offset(0, 0) = lblcodigopost And ActiveCell.Offset(0, 1) <> Empty And ActiveCell.Offset(0, 12) = Txtpostventas.Text And ActiveCell.Offset(0, 6).Value = 1 Then
LOC = LOC + 1
End If
ActiveCell.Offset(1, 0).Select
Loop
COLMTX = LOC + 2
'Situcacion en la cual la Postventa no tiene locativa
If COLMTX = 2 Then
COLMTX = 3
End If
ReDim mtxlocat(COLMTX, 3)
ReDim mtx_loc_fin(COLMTX, 3)
Range("H4").Select
X1 = 2
'CODIGO
mtxlocat(0, 0) = "CODIGO"
'DESCRIPCION
mtxlocat(0, 1) = "DESCRIPCION"
'GRUPO
mtxlocat(0, 2) = "GRUPO"
'CODIGO
mtx_loc_fin(0, 0) = "CODIGO"
'DESCRIPCION
mtx_loc_fin(0, 1) = "DESCRIPCION"
'GRUPO
mtx_loc_fin(0, 2) = "GRUPO"
Do Until ActiveCell.Offset(0, 0) = ""
If ActiveCell.Offset(0, 0) = lblcodigopost And COLMTX = 3 And ActiveCell.Offset(0, 12) = Txtpostventas.Text And ActiveCell.Offset(0, 6).Value = 1 Then
'CODIGO
mtxlocat(X1, 0) = ActiveCell.Offset(0, 1)
'DESCRIPCION
mtxlocat(X1, 1) = ActiveCell.Offset(0, 2)
'GRUPO
mtxlocat(X1, 2) = ActiveCell.Offset(0, 3)
X1 = X1 + 1
Else
If ActiveCell.Offset(0, 0) = lblcodigopost And ActiveCell.Offset(0, 1) <> Empty And COLMTX > 3 And ActiveCell.Offset(0, 12) = Txtpostventas.Text And ActiveCell.Offset(0, 6).Value = 1 Then
'CODIGO
mtxlocat(X1, 0) = ActiveCell.Offset(0, 1)
'DESCRIPCION
mtxlocat(X1, 1) = ActiveCell.Offset(0, 2)
'GRUPPO
mtxlocat(X1, 2) = ActiveCell.Offset(0, 3)
X1 = X1 + 1
End If
End If
ActiveCell.Offset(1, 0).Select
Loop
CODLOCATIVAS.List() = mtxlocat
Sheets("CUADRO DE LOCATIVAS").Select
SOLUC.Enabled = True
Application.ScreenUpdating = True
End Sub
1 Respuesta
Respuesta de Dante Amor
1

