Loop na planilha

Guarino

27-08-2018 15:30:45

Pessoal, bom dia!

tenho essa macro de busca que um amigo me ajudou:

ela busca todas as palavra em ART. 152 , artigo 114, art. 221 e ARTIGO 38

1° Porem, quando a palavra é b]ART.152[/b] , artigo.114, art.221 e ARTIGO.38 com o ponto junto da palavra ela não puxa.

2° Gostaria q a macro fizesse um loop na coluna A até a ultima linha da planiha, pq ela tem em média 20.000 linhas e que a resposta viesse normalmente como vem nas colunas no lado, resumindo: ela está fixa somente em uma célula e não está percorrendo...

alguém poderia me ajudar adaptar ela?

Sub ExtraiArtigos()
Dim wrdTexto() As String, i As Long, strg As String, k As Long
Dim strTexto As String
strTexto = Replace(Replace([A2], ",", " "), "º", "º ")
wrdTexto() = Split(strTexto)
For i = LBound(wrdTexto) To UBound(wrdTexto) - 1
If InStr(1, wrdTexto(i), "art") > 0 Or InStr(1, wrdTexto(i), "ART") > 0 And _
IsNumeric(Left(wrdTexto(i + 1), 1)) Then
Cells(1, k + 2) = wrdTexto(i) & " " & wrdTexto(i + 1): k = k + 1
End If
Next i
End Sub

Obrigado

segue planilha em anexo

Reinaldo

27-08-2018 16:16:18

Talvez assim:

Código: Selecionar todos

Sub ExtraiArtigos()
Dim wrdTexto() As String, strTexto As String
Dim i As Long, k As Long, lRow As Long, x As Long
'Determina o numero delinhas preenchidas na coluna A
lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
k = 0

'inicia loop para leitura da coluna A
For x = 2 To lRow

    strTexto = Replace(Replace(Cells(x, 1), ",", " "), "º", "º ")
    strTexto = Replace(Replace(Cells(x, 1), ".", ". "), "  ", " ")   
    wrdTexto() = Split(strTexto)
    
    For i = LBound(wrdTexto) To UBound(wrdTexto) - 1
        If InStr(1, UCase(wrdTexto(i)), "ART.") > 0 Or InStr(1, UCase(wrdTexto(i)), "ART ") > 0 And _
            IsNumeric(Left(wrdTexto(i + 1), 1)) Then
            Cells(x, k + 2) = wrdTexto(i) & " " & wrdTexto(i + 1): k = k + 1
        End If
    Next i
k = 0
Next x
End Sub

Guarino

27-08-2018 16:52:48

Olá, meu amigo, deu certinho!!!

Muito obrigado pela ajuda!!!

só mias uma ajuda, no caso a busca está na coluna E e a resposta teria que vim a partir da coluna F..

como posso alterar isso?

Obrigado!

Reinaldo

27-08-2018 17:43:23

Em cells(x,"A"), o primeiro termo x indica a linha, e o segundo a coluna. A sintaxe é-->cells(Linha,Coluna), e coluna pode ser indicada pela sua letra(entre aspas) ou seu numero posicional A=1, b=2...E=5.....

Alterar onde refere-se a cells... para as suas colunas
lRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
strTexto = Replace(Replace(Cells(x, "E"), ",", " "), "º", "º ")
strTexto = Replace(Replace(Cells(x, "E"), ".", ". "), " ", " ")
Cells(x, k + 6) = wrdTexto(i) & " " & wrdTexto(i + 1): k = k + 1

Guarino

27-08-2018 18:13:38

Sub ExtraiArtigos()
Dim wrdTexto() As String, strTexto As String
Dim i As Long, k As Long, lRow As Long, x As Long
'Determina o numero delinhas preenchidas na coluna A
lRow = Cells(Cells.Rows.Count, "E").End(xlUp).Row
k = 0

'inicia loop para leitura da coluna A
For x = 2 To lRow

strTexto = Replace(Replace(Cells(x, "E"), ",", " "), "º", "º ")
strTexto = Replace(Replace(Cells(x, "E"), ".", ". "), " ", " ")
wrdTexto() = Split(strTexto)

For i = LBound(wrdTexto) To UBound(wrdTexto) - 1
If InStr(1, UCase(wrdTexto(i)), "ART.") > 0 Or InStr(1, UCase(wrdTexto(i)), "ART") > 0 And _
IsNumeric(Left(wrdTexto(i + 1), 1)) Then
Cells(x, k + 6) = wrdTexto(i) & " " & wrdTexto(i + 1): k = k + 1
End If
Next i
k = 0
Next x

MsgBox "Artigos Extraídos com sucesso!"

End Sub

Obrigado novamente!