Sunteți pe pagina 1din 2

buscarv y valores repetidos Sub busca_grupo() 'Miller burbano Dim b As Variant Dim r As Range Dim fila As Long On Local

Error GoTo errores b = Trim(InputBox("indica valor a buscar", "Buscar", 0)) If Application.WorksheetFunction.CountA(ActiveSheet.Range("A:A")) = 0 Then Exit Sub Set r = Application.InputBox("selecciona el rango", , , , , , , Type:=8) If Application.WorksheetFunction.CountIf(r, b) = 0 Then MsgBox "no existe el dat o buscado", vbCritical: GoTo 1 fila = Application.WorksheetFunction.CountA(Sheets("Hoja2").Range("A:a")) + 1 For Each r In Range(r.Address) If b = CStr(r) Then Sheets("Hoja2").Range("a" & fila) = r.Offset(0, -1) Sheets("Hoja2").Range("b" & fila) = r Sheets("Hoja2").Range("c" & fila) = r.Offset(0, 13) fila = Application.WorksheetFunction.CountA(Sheets("Hoja2").Range("A:a")) + 1 End If Next 1: Set r = Nothing errores: If Err.Number <> 0 Then Set r = Nothing: MsgBox Err.Number & " " & Err.Descripti on End Sub

################################################################################ ## Private Sub busca_grupo() '4c7569735f50 Dim b As Variant Dim r As Range Dim fila As Long On Local Error GoTo errores b = Trim(InputBox("indica valor a buscar", "Buscar", 0)) If Application.WorksheetFunction.CountA(ActiveSheet.Range("A:A")) = 0 Then Exit Sub Set r = Application.InputBox("selecciona el rango", , , , , , , Type:=8) If Application.WorksheetFunction.CountIf(r, b) = 0 Then MsgBox "no existe el dat o buscado", vbCritical: GoTo 1 fila = Application.WorksheetFunction.CountA(Sheets(2).Range("A:a")) + 1 For Each r In Range(r.Address) If b = CStr(r) Then Sheets(2).Range("a" & fila) = r.Offset(0, -1) Sheets(2).Range("b" & fila) = r

Sheets(2).Range("c" & fila) = r.Offset(0, 1) fila = Application.WorksheetFunction.CountA(Sheets(2).Range("A:a")) + 1 End If Next 1: Set r = Nothing errores: If Err.Number <> 0 Then Set r = Nothing: MsgBox Err.Number & " " & Err.Descripti on End Sub

################################################################################ ####### funciona asi: al ejecutar el macro "busca_grupo" aparecera un cuadro de dialogo que te pide que edites el valor a buscar luego aparecera otro cuadro que te pedira identificar el rango completo de los c odigos que se recorrera, en este caso desde b2 hasta b(n...) asi el macro recorrera cada una de las filas de ese rango y comparara su conteni do v/s el valor buscado si hay coincidencia pasara los valores de "resumen" a la hoja2 si deseas que se pasen a una hoja diferente... solo cambias el indice Sheets(2) por el numero que desees importante es que no existan filas vacias en la tabla de recorrido ( valores ori ginales)

S-ar putea să vă placă și