locked
Comparação de valores gerando falha RRS feed

  • Pergunta

  • Prezados,

     

    Boa tarde!!

     

    Dêem uma olhada no código:

     

    vou comentar o primeiro IF porém todos os outros estão idênticos, modificando-se apenas os valores necessários, porém as linhas de comando são idênticas

     

    If Range("G23").Value = A1 Then                       -             comparando o valor da Célula G23 com A1. A1 não é a célula.


        ActiveWindow.SmallScroll Down:=50
        Range("O62Stick out tongue62").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select

     

    Se o valor selecionado na combo-box que tem na célula G23 for A1, o programa deve selecionar a célula O62Stick out tongue62 e colar especial em cima dela mesma.

     

    Alguém intende porque não funciona?

     

    A finalidade do programa é gerar Etiquetas patrimoniais com código de barras. Se tiverem algo parecido e puderem contribuir, agradeço!!

     

    Segue o código completo:

     

    Sub A()
    '
    ' A Macro
    ' Macro gravada em 3/1/2008 por LinkCom
    '

        If Range("G23").Value = A1 Then
           
        ActiveWindow.SmallScroll Down:=50
        Range("O62Stick out tongue62").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
               
        ElseIf Range("G23").Value = A2 Then
           
        ActiveWindow.SmallScroll Down:=50
        Range("O63Stick out tongue63").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = A3 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O64Stick out tongue64").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = A4 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O65Stick out tongue65").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
             
        ElseIf Range("G23").Value = A5 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O66Stick out tongue66").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = A6 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O67Stick out tongue67").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
           
        ElseIf Range("G23").Value = A7 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O68Stick out tongue68").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
                  
        ElseIf Range("G23").Value = A8 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O69Stick out tongue69").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = A9 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O70Stick out tongue70").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = A10 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O71Stick out tongue71").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
          
        ElseIf Range("G23").Value = A11 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O72Stick out tongue72").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = B1 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O73Stick out tongue73").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
               
        ElseIf Range("G23").Value = B2 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O74Stick out tongue74").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = B3 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O75Stick out tongue75").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
           
        ElseIf Range("G23").Value = B4 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O76Stick out tongue76").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
               
        ElseIf Range("G23").Value = B5 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O77Stick out tongue77").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = B6 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O78Stick out tongue78").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = B7 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O79Stick out tongue79").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = B8 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O80Stick out tongue80").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
              
        ElseIf Range("G23").Value = B9 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O81Stick out tongue81").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
           
        ElseIf Range("G23").Value = B10 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O82Stick out tongue82").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = B11 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O83Stick out tongue83").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C1 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O84Stick out tongue84").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C2 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O85Stick out tongue85").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
           
        ElseIf Range("G23").Value = C3 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O86Stick out tongue86").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C4 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O87Stick out tongue87").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C5 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O88Stick out tongue88").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C6 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O89Stick out tongue89").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C7 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O90Stick out tongue90").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C8 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O91Stick out tongue91").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C9 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O92Stick out tongue92").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C10 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O93Stick out tongue93").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        ElseIf Range("G23").Value = C11 Then
       
        ActiveWindow.SmallScroll Down:=50
        Range("O94Stick out tongue94").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=-65
        Range("A9").Select
       
        End If
       
       
          
    End Sub

    quinta-feira, 3 de janeiro de 2008 18:07

Todas as Respostas

  • Vc poderia esclarecer 2 pontos?

    1. Qual o problema que está ocorrendo quando diz que não funciona? (a macro trava? ocorre processamento, mas o resultado não é o desejado? outro?)

    2. Qual o tipo de valor que está armazenado nas variáveis Ak, Bk e Ck.

     

    De cara, já podemos encurtar o teu código utilizando alguns conceitos difererentes.

    Ficariamos, por exemplo, para o teste até A3 com o seguinte código

    Sub A()

    Dim i As Integer
    Dim Valor

    Valor = Range("G23").Value
    Select Case Valor
    Case A1
    i = 1
    Case A2
    i = 2
    Case A3
    i = 3
    End Select
    ActiveWindow.SmallScroll Down:=50
    Range(Cells(62 + i, 15), Cells(62 + i, 16)).Copy
    ActiveWindow.SmallScroll Down:=-65
    Cells(9, 1).Select

    End Sub

     

    Espero a resposta das questões acima para continuar a auxiliá-lo.

    []s

    sexta-feira, 4 de janeiro de 2008 19:28
  • olha,pelo q eu entendi vc nao teria que comparar com o valor da celula e sim com o valor da combo-box se a combo-box for um objeto,agora se ela não for eu nao consegui entender como você escolhe esses dados..

     

    se for um objeto o codigo ficaria mais ou menos assim:

     

    If Combobox1.value="A1" then(...)

     

    nesse exemplo o nome da combo box é Combobox1,porem pode ser q o nome seja outro.

     

    espero ter ajudado

    boa sorte

    XoX

    quarta-feira, 16 de janeiro de 2008 13:57