How to export a data matrix?

0

What I need to do is something complex so I will try to explain myself as best as possible ...

It turns out that I have this form

In this form, the user must first select a chapter, then a subchapter and finally an item, as soon as the item is selected, the information of "Code" "Description" and "Unit" will be automatically brought to the Listbox, if the you want to see the rest of the data you must click on the "View APU" button, and at that moment the program should go to the following database and bring the data that I will indicate

Taking as an example the user to choose "STC base asf.-4% asf, ag.1.5" ", the program should take all those data that are highlighted, the same if he had chosen another item (the red ones ) should be the range between one item and another, but as I said the changing range between one item and another there may be 2 items and in other parts 12, so I do not know how to take the specific range I need. . I hope you have made me understand, any additional information with pleasure you give them.

P.D: This is the code I use to search the data

If Me.cbxitm.Value = "" Or Me.cbxitm.Value = " " Then
Me.lbxAPU.Clear
Else
Me.lbxAPU.Clear
j = 1
Set Db = ThisWorkbook.Sheets("APU")
Filas = Db.Range("C2").CurrentRegion.Rows.Count
Me.lbxAPU.RowSource = ""
For I = 2 To Filas
    If LCase(Db.Cells(I, j).Offset(0, 2).Value) Like "*" & LCase(Me.cbxitm.Value) & "*" Then
        Me.lbxAPU.AddItem Db.Cells(I, j).Offset(0, 1)
        Me.lbxAPU.List(Me.lbxAPU.ListCount - 1, 1) = Db.Cells(I, j).Offset(0, 2)
        Me.lbxAPU.List(Me.lbxAPU.ListCount - 1, 2) = Db.Cells(I, j).Offset(0, 3)
    Else
    End If
Next I
    
asked by Juan Arango 05.03.2018 в 14:16
source

1 answer

0

One solution can be to make a counter from the cell where the searched reference starts and from there count row by row until you find a new reference.

We will know this by evaluating the number of characters in the [Código] field with the LEN function. Once you have many rows it is already easy to select the ranges you want.

Example of how it can work:

Sub copyrange()

Dim i, j As Integer

j = 1 'Inicia conteo en 1 para incluir la primera fila donde la referencia inicia y la condición es igual a 7 caracteres.
For i = 1 To Filas 'i = numero de fila donde se encuentra la celda con el código de referencia buscado.
    If Len(Db.Cells(i, 2).Value) <> 7 Then 'Se evalúa si cada celda es diferente a 7 caracteres.
        j = j + 1 'si lo es entonces sume uno a nuestro contador j.
    Else
        Exit For 'Al llegar al siguiente código este tiene 7 caracteres por lo cual no sumara mas a el contador y terminara el ciclo for.
    End If
Next i

Db.Range("B" & i, "F" & j).Select 'Ya puede seleccionar el rango entre la fila i inicial hasta la fila j final entre las columnas B y F.

End Sub
    
answered by 05.03.2018 / 19:49
source