Notifications
Clear all

pesquisar serie de dados e colar o valor

8 Posts
2 Usuários
0 Reactions
2,208 Visualizações
(@dlhunsil)
Posts: 21
Eminent Member
Topic starter
 

não sei oq ta acontecendo mas criei essa macro e na segunda vez q ele não acha nenhum valor ele da erro no tempo de execução 91
a função dessa macro é procurar uma informação da linha em um espaço e retomar o valo correspondente ao valor procurado

Sub Valor pago()
'
' valor pago
'

'
Dim a As String

Dim continua As VbMsgBoxResult

p = 0
i = 1

While p < 10

Range("A1").Select

a = Cells(1, i)

ActiveCell.Offset(6, 0).Range("A1:H9").Select
MsgBox (a)

On Error GoTo fim:

Selection.Find(What:=a, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
continua = MsgBox("Resultado é correto?", vbYesNo, "decidindo o valor")

If continua = vbYes Then
ActiveCell.Offset(0, 2).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Range("A1").Select
i = i - 1
ActiveCell.Offset(1, i).Range("A1").Select
i = i + 1

ActiveSheet.Paste

Else
On Error GoTo fim:
End If
fim:

p = p + 1
i = i + 1

Wend
End Sub

 
Postado : 18/01/2012 5:35 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Veja se isso te ajuda...

Sub Valorpago()
    Dim a      As String
    Dim continua As VbMsgBoxResult
    Dim p      As Long
     
    p = 0
    i = 1
    Range("A1").Select
    While p < 10
        a = Cells(1, i)
        ActiveCell.Offset(6, 0).Range("A1:H9").Select
        MsgBox (a)
        If Not IsEmpty(a) Then
            With Selection
                .Find(What:=a, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
                xlNext, MatchCase:=False, SearchFormat:=False).Activate
                continua = MsgBox("Resultado é correto?", vbYesNo, "decidindo o valor")
            End With
            If continua = vbYes Then
                i = i - 1
                ActiveCell.Offset(0, 2).Range("A1").Copy ActiveCell.Offset(1, i)
                i = i + 1
            End If
        End If
        p = p + 1
        i = i + 1
    Wend
End Sub

Dê retorno ;)

 
Postado : 19/01/2012 5:46 am
(@dlhunsil)
Posts: 21
Eminent Member
Topic starter
 

não funcionou o erro q esta dando é q a variavel do objeto ou a variavel do bloco "with" não fou definida

oq eu preciso na minha estrutura é uma forma de ele ficar fazendo o lopp ate o fim da estrutura while, se ele encontra o erro ele vá para o fim: e comece denovo pois o valor da variavel "a" foi trocado.

pelo q eu percebi ele esta dando erro como se a estrutura estivesse dando o mesmo erro varias vezes ele não reconhece q o valor de " a " foi trocado

 
Postado : 19/01/2012 6:20 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Veja se isso vai funcionar..

Sub Valorpago() 
    Dim a      As String 
    Dim continua As VbMsgBoxResult 
    Dim p      As Long 
    On Error Resume Next 
    p = 0 
    i = 1 
    Range("A1").Select 
    While p < 10 
        a = Cells(1, i) 
        ActiveCell.offset(6, 0).Range("A1:H9").Select 
        MsgBox (a) 
        If Not IsEmpty(a) Then 
            With Selection 
                .Find(What:=a, After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _ 
                xlNext, MatchCase:=False, SearchFormat:=False).Activate 
                continua = MsgBox("Resultado é correto?", vbYesNo, "decidindo o valor") 
            End With 
            If continua = vbYes Then 
                i = i - 1 
                ActiveCell.offset(0, 2).Range("A1").Copy ActiveCell.offset(1, i) 
                i = i + 1 
            End If 
        End If 
        p = p + 1 
        i = i + 1 
    Wend 
End Sub 
 
Postado : 19/01/2012 6:28 am
(@dlhunsil)
Posts: 21
Eminent Member
Topic starter
 

Muito obrigado resolveu meu principal problema.
oq ocorre agora é que se vc notar na minha função ele copia e cola determinado valor, agora onde daria o erro ele esta pegando o valor de dua colunas a frente
o importante q onde ta certo ele esta pegando o valor CORRETAMENTE

te agradeço muito

 
Postado : 19/01/2012 7:09 am
(@dlhunsil)
Posts: 21
Eminent Member
Topic starter
 
Dim a As String
Dim continua As VbMsgBoxResult
Dim p As Long

On Error Resume Next

p = 0
i = 1

While p < 10
    Range("A1").Select
    a = Cells(1, i)
    ActiveCell.Offset(6, 0).Range("A1:H9").Select
    MsgBox (a)
    If Not IsEmpty(a) Then
        With Selection
                .Find(What:=a, After:=ActiveCell, LookIn:= _
            xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
            xlNext, MatchCase:=False, SearchFormat:=False).Activate
        End With
        continua = MsgBox("Resultado é correto?", vbYesNo, "decidindo o valor")
    If continua = vbYes Then
        ActiveCell.Offset(0, 2).Range("A1").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("A1").Select
        i = i - 1
        ActiveCell.Offset(1, i).Range("A1").Select
        i = i + 1
        ActiveSheet.Paste
    End If
    End If
    p = p + 1
    i = i + 1
Wend
End Sub
 
Postado : 19/01/2012 7:25 am
(@dlhunsil)
Posts: 21
Eminent Member
Topic starter
 

Como eu faço para colocar [resolvido] no topico?

 
Postado : 31/01/2012 2:08 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

boa noite!!!

Veja no anexo.

Na parte superior das resposta de quem te ajudou..

 
Postado : 31/01/2012 5:48 pm