Ajuda para copiar o resultado de uma macro

Lu Belchior

New Member
Joined
Sep 18, 2008
Messages
1
Olá, não sou muito experiente com o assunto, mas através das dicas do forum consegui criar uma planilha que possui duas abas.
Uma das abas tem o banco de dados que é alimentado automaticamente por uma consuta(query) ao Banco Oracle.
Na outra aba fiz uma macro que me diz se determinado valor encontra-se na outra planilha, quantas vezes e em quais linhas.
O que eu quero agora é ao clicar em "OK" da caixa de texto, automaticamente essas linhas que foram encontardas possam ser copiadas e aparecerem pra mim nessa outra aba.
a macro roda com o seguinte código:

Code:
Sub CNPJ()
'
' CNPJ Macro
' Macro gravada em 27/01/2009 por XXXXXXXXX
' Public Sub FindText()
' Run from standard module, like: Module1.
    
    Dim ws As Worksheet, Found As Range
    Dim myText As String, FirstAddress As String
    Dim AddressStr As String, foundNum As Integer
    
    myText = InputBox("Informar Dados de Consulta")
    If myText = "" Then Exit Sub
    For Each ws In ThisWorkbook.Worksheets
        With ws
            Set Found = .UsedRange.Find(what:=myText, LookIn:=xlValues, MatchCase:=False)
            If Not Found Is Nothing Then
                FirstAddress = Found.Address
                Do
                    foundNum = foundNum + 1
                    AddressStr = AddressStr & .Name & " " & Found.Address & vbCrLf
                    Set Found = .UsedRange.FindNext(Found)
                Loop While Not Found Is Nothing And Found.Address <> FirstAddress
            End If
        End With
    Next ws
    If Len(AddressStr) Then
        MsgBox "Encontradas: """ & myText & """ " & foundNum & " vezes." & vbCr & _
               AddressStr, vbOKOnly, myText & " nessas células"
    Else
        MsgBox "Não foram encontrados registros com os dados informados " & myText & " nessa consuta.", vbExclamation
    End If
End Sub

Alguém pode me ajudar com esse projeto ?
 
Last edited by a moderator:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Bienvenido a MrExcel.

¿Usted quiere que el macro haga una hoja nueva? ¿O que aparezcan en una hoja existente? ¿Desea copiar todas las células de la línea que coincidiaron? (Me imagino que sí porque de otra manera no tiene sentido.)
 
Upvote 0

Forum statistics

Threads
1,215,340
Messages
6,124,386
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top