La idea es esta creas el formulario que te indique con un cambio el label2 ahora te indicara el nombre de producto que elijas del combobox, label3 la definió como resumen y en el formulario pegas el siguiente código
esta es la macro que debes pegar en el formulario, después en un modulo estándar pegas el código más abajo, la macro cargara los datos de la hoja producto ene l combobox y luego dependiendo de cual escojas te cargara en el listbox y en la hoja reporte un resumen del código a buscar y una vez que des click en el botón te lo enviara a un nuevo libro sin modificar nada en las hojas producto ni relacion_ordenes
Private Sub ComboBox1_Change()
Set lista = Range("lista"): Set productos = Range("PRODUCTOS")
Set funcion = WorksheetFunction: valor = ComboBox1.Value
With lista
If valor <> vbNullString Then
fila = funcion.Match(Val(valor), .Columns(1), 0)
Label2 = .Cells(fila, 2)
End If
End With
With productos
.Columns(.Columns.Count + 3).CurrentRegion.Clear
On Error Resume Next
fila = funcion.Match(Val(valor), .Columns(7), 0)
On Error GoTo 0
registros = funcion.CountIf(.Columns(7), Val(valor))
If registros > 0 Then
Set detalle = .Rows(fila).Resize(registros, .Columns.Count)
Set articulos = .Columns(.Columns.Count + 3).Resize(registros, .Columns.Count)
articulos.Rows(0).Value = .Rows(0).Value
articulos.Value = detalle.Value
articulos.CurrentRegion.Name = "destino"
With ListBox1
.ColumnCount = productos.Columns.Count
.ColumnHeads = True
.ColumnWidths = "80;160;80;60;60;60;40;40;180"
.RowSource = "hoja_reporte!" & articulos.Address
End With
End If
End With
End Sub
Private Sub CommandButton1_Click()
Set DESTINO = Range("DESTINO")
LIBRO = ActiveWorkbook.Name
Set nuevo = Workbooks.Add
With DESTINO
Range("B2").Resize(.Rows.Count, .Columns.Count).Value = _
DESTINO.Value
End With
Workbooks(LIBRO).Activate
End Sub
Private Sub UserForm_Initialize()
Dim UNICOS As New Collection
ANALIZAR_INFORMACION
Set hp = Worksheets("productos")
Set productos = hp.Range("a1").CurrentRegion
With productos
Set productos = .Rows(2).Resize(.Rows.Count - 1, 2)
.Name = "lista"
matriz = productos
With ComboBox1
.ColumnCount = productos.Columns.Count
.ColumnWidths = "20;60"
.List = matriz
.ListIndex = 0
End With
End With
Set producto = Nothing
End Sub
Sub ANALIZAR_INFORMACION()
Set H1 = Worksheets("relacion_ordenes")
Set h2 = Worksheets("Hoja_reporte")
Set datos = H1.Range("B2").CurrentRegion
h2.Cells.Clear
With datos
COLUMNA = H1.Range("G1").Column
COLUMNAS = .Columns.Count
DIFERENCIA = COLUMNAS - COLUMNA
Set datos = .Rows(2).Resize(.Rows.Count - 1)
Set DATOS2 = .Columns(COLUMNA).Resize(.Rows.Count, DIFERENCIA + 1)
Set DATOS3 = .Resize(.Rows.Count, COLUMNA - 1)
DIVIDIR = (DIFERENCIA + 1) / 3: FILAS = .Rows.Count
End With
With DATOS3
For i = 1 To DIVIDIR
If i = 1 Then
Set DESTINO = h2.Range("B3").Resize(FILAS, COLUMNA - 1)
Set producto = .Columns(COLUMNA).Resize(FILAS, 3)
End If
If i > 1 Then
Set DESTINO = DESTINO.Rows(FILAS + 1).Resize(FILAS, COLUMNA - 1)
Set producto = producto.Columns(4).Resize(FILAS, 3)
End If
DESTINO.Value = .Value
DESTINO.Columns(COLUMNA).Resize(FILAS, 3).Value = _
producto.Value
Next i
End With
With DESTINO.CurrentRegion
.Name = "PRODUCTOS"
.Sort KEY1:=h2.Range(.Columns(7).Address), ORDER1:=xlAscending
.Rows(0).Value = DATOS3.Rows(0).Value
.EntireColumn.AutoFit
.Cells(0, 7) = "Item"
.Cells(0, 8) = "Cant"
.Cells(0, 9) = "det"
End With
End Sub