Excel - hacer un bucle

 
Vista:

hacer un bucle

Publicado por Florencia (1 intervención) el 13/09/2017 15:40:09
EL macro consiste en los siguiente… busca el valor de la celda “A2” de la “Hoja 1” en la hoja "RECETAS (2)" y devuelve todos los valores de la columna “C” que son los ingredientes (Esto lo hace con el Do).

Necesitaríamos crear un bucle para que agregue filas dependiendo de la cantidad de ingredientes que ya agregó, es decir que agregue “J”.
SI se copian 4 ingredientes hay que agregar 4 filas.
Este es el macro que tenemos, funciona pero solo devuelve el dato de la celda a2 no sigue leyendo y haciendo lo mismo con todos los datos de la columna a

Gracias!!!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Sub filtrar2()
 
    Set h1 = Sheets("RECETAS (2)")
    Set h2 = Sheets("Hoja1")
    u2 = h2.Range("b" & Rows.Count).End(xlUp).Row
    If u2 < 2 Then u2 = 2
    h2.Range("c" & u2 & ":c" & u2).ClearContents
    j = 2
  celda = "a2"
 
  Set r = h1.Columns("a")
    Set b = r.Find(h2.Range(celda), lookat:=xlWhole)
 
    If Not b Is Nothing Then
        ncell = b.Address
        Do
            h1.Range(h1.Cells(b.Row, "c"), h1.Cells(b.Row, "c")).Copy
 
            h2.Cells(j, 2).PasteSpecial Paste:=xlValues
            j = j + 1
            Set b = r.FindNext(b)
 
        Loop While Not b Is Nothing And b.Address <> ncell
 
    End If
 
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder