Vídeo recomendado
https://youtu.be/diWPPPhW-9E

SOMATÓRIO - INDICE E CORRESP VBA

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
JONATHA123
Colaborador
Colaborador
Mensagens: 57
Registrado em: Sáb Set 30, 2017 2:26 pm

SOMATÓRIO - INDICE E CORRESP VBA

Mensagem por JONATHA123 »

Boa tarde.
Novamente peço a ajuda de vcs, quando verificarem a planilha foquem na plan5, nela que preciso de ajuda... a plan1 é a planilha de vendas ok? nela que se imprime os recibos aqui... quando vc da "crtl+p" ela imprime e automaticamente manda os dados da plan1 para a plan5 (relatório semanal) e plan6 (histórico de recibos emitidos), exclusivamente os clientes teste1 e teste2 são gravados na plan5 e plan6 simuntaneamente (somente as celulas A3, B3 e B10 são gravadas na plan5). Todos os outros clientes são gravados somente em histórico, enfim essa explicação é só para explicar mesmo como funciona... pois já esta tudo feito em módulos...o que eu quero é que na plan5, quando forem gravados os clientes
teste1 e teste2, se eles compraram mais um tipo de mercadoria (celulas de A4 a A9 da plan1) apareça tudo isso na planilha selecionada em plan5, igual a foto abaixo. Para isso... clique duas vezes na célula H6 e escolha o cliente teste1 ou teste2 ai aparecera o resultado... se caso esses cliente comprarem
mais de uma mercadoria (tipo2, tipo3...etc) esses valores das outras mercadorias devem ser somados e colocados na planilha selecionada (coluna F), e sua multiplicação pelo preço correto (coluna G) - planilha que mostrei na foto detalha melhor isso.
Anexos
TESTE.rar
(64.44 KiB) Baixado 205 vezes
Capturar.PNG
Capturar.PNG (33.21 KiB) Exibido 2196 vezes


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


JONATHA123
Colaborador
Colaborador
Mensagens: 57
Registrado em: Sáb Set 30, 2017 2:26 pm

Re: SOMATÓRIO - INDICE E CORRESP VBA

Mensagem por JONATHA123 »

PARA MELHOR EXPLICAR ESTA O CODIGO ABAIXO PARA FAZER ALGUMAS MUDANÇAS:

Código: Selecionar todos

Option Explicit
Private TextoDigitado As String

Private Sub ListBox2_Click()
    ActiveCell.Value = ListBox2.Value
    Range("R8:T80").Interior.Color = RGB(255, 255, 255)
    Range("R8:T80").Font.Color = RGB(0, 0, 0)
    retorndaDadosCliente ListBox2
    defineAreaImpressão ActiveSheet.Name
    Unload Me
    Range("R1").Activate
End Sub

Private Sub TextBox2_Change()
    TextoDigitado = TextBox2.Text
    Call PreencheLista
End Sub


Private Sub UserForm_Initialize()
    Call PreencheLista
End Sub

Private Sub PreencheLista()
    Dim ws As Worksheet
    Dim i As Integer
    Dim TextoCelula As String
    Set ws = ThisWorkbook.Worksheets(2)
    i = 2
    ListBox2.Clear
    With ws
        While .Cells(i, 1).Value <> Empty
            TextoCelula = .Cells(i, 1).Value
            If UCase(Left(TextoCelula, Len(TextoDigitado))) = UCase(TextoDigitado) Then
                ListBox2.AddItem .Cells(i, 1)
            End If
            i = i + 1
        Wend
    End With
End Sub

Function retorndaDadosCliente(ByVal nome As String)
    Dim valorcliente
        valorcliente = Application.WorksheetFunction.VLookup(nome, ThisWorkbook.Sheets("clientevalor").Range("A2:D10000"), 4, False)
        
    With ThisWorkbook.Sheets("RelatórioSemanal")
       .Activate
        Dim ultimaLinha As Integer
        ultimaLinha = .UsedRange.Rows.Count
        
        Range("R8:T100").Select
        Selection.ClearContents

        Dim rangeRelatorio As Range
        Dim produto As String
        Dim DATA As Date
        
        Dim VALOR As Double
        Dim VALOR1 As Double
        Dim VALOR2 As Double
        Dim VALOR3 As Double
        Dim VALOR4 As Double
        Dim VALOR5 As Double
        Dim VALOR6 As Double
        Dim VALOR7 As Double
        Dim VALOR8 As Double
        Dim VALOR9 As Double
        Dim VALOR10 As Double
        Dim VALOR11 As Double
        Dim VALOR12 As Double
        Dim VALOR13 As Double
        Dim VALOR14 As Double
        
        Dim rLinha As Integer
        rLinha = 8
        
        Dim somaValores
        somaValores = 0
        Dim somaValores1
        somaValores1 = 0
        Dim somaValores2
        somaValores2 = 0
        Dim somaValores3
        somaValores3 = 0
        Dim somaValores4
        somaValores4 = 0
        Dim somaValores5
        somaValores5 = 0
        Dim somaValores6
        somaValores6 = 0
        Dim somaValores7
        somaValores7 = 0
        Dim somaValores8
        somaValores8 = 0
        Dim somaValores9
        somaValores9 = 0
        Dim somaValores10
        somaValores10 = 0
        Dim somaValores11
        somaValores11 = 0
        Dim somaValores12
        somaValores12 = 0
        Dim somaValores13
        somaValores13 = 0
        Dim somaValores14
        somaValores14 = 0
        
        Dim vLinha As Integer
        
        For vLinha = 2 To ultimaLinha
            
            Cells(vLinha, "A").Select
            
            If Cells(vLinha, "A") = "" Then Exit For
            
            If Cells(vLinha, "A") <> "" Then
                
                If ActiveCell = nome Then
                    
                    VALOR = ActiveCell.Offset(0, 1)
                    VALOR1 = ActiveCell.Offset(0, 2)
                    VALOR2 = ActiveCell.Offset(0, 3)
                    VALOR3 = ActiveCell.Offset(0, 4)
                    VALOR4 = ActiveCell.Offset(0, 5)
                    VALOR5 = ActiveCell.Offset(0, 6)
                    VALOR6 = ActiveCell.Offset(0, 7)
                    VALOR7 = ActiveCell.Offset(0, 8)
                    VALOR8 = ActiveCell.Offset(0, 9)
                    VALOR9 = ActiveCell.Offset(0, 10)
                    VALOR10 = ActiveCell.Offset(0, 11)
                    VALOR11 = ActiveCell.Offset(0, 12)
                    VALOR12 = ActiveCell.Offset(0, 13)
                    VALOR13 = ActiveCell.Offset(0, 14)
                    VALOR14 = ActiveCell.Offset(0, 15)
                    DATA = ActiveCell.Offset(0, 16)
                    
                    Cells(rLinha, "T") = CDate(DATA)
                    Cells(rLinha, "S") = Format(VALOR, "###0.00")
                    Cells(rLinha, "R") = "F. ABATIDO"
                    somaValores = somaValores + VALOR
                    
                    Cells(rLinha + 4, "S") = Format(VALOR1, "###0.00")
                    Cells(rLinha + 4, "R") = "F. VIVO"
                    Cells(rLinha + 4, "T") = CDate(DATA)
                    somaValores1 = somaValores1 + VALOR1

                    Cells(rLinha + 8, "S") = Format(VALOR2, "###0.00")
                    Cells(rLinha + 8, "R") = "COXA"
                    Cells(rLinha + 8, "T") = CDate(DATA)
                    somaValores2 = somaValores2 + VALOR2
                    
                    Cells(rLinha + 12, "S") = Format(VALOR3, "###0.00")
                    Cells(rLinha + 12, "R") = "PEITO"
                    Cells(rLinha + 12, "T") = CDate(DATA)
                    somaValores3 = somaValores3 + VALOR3
                    
                    Cells(rLinha + 16, "S") = Format(VALOR4, "###0.00")
                    Cells(rLinha + 16, "R") = "ASA"
                    Cells(rLinha + 16, "T") = CDate(DATA)
                    somaValores4 = somaValores4 + VALOR4
                    
                    Cells(rLinha + 20, "S") = Format(VALOR5, "###0.00")
                    Cells(rLinha + 20, "R") = "CORAÇÃO"
                    Cells(rLinha + 20, "T") = CDate(DATA)
                    somaValores5 = somaValores5 + VALOR5

                    Cells(rLinha + 24, "S") = Format(VALOR6, "###0.00")
                    Cells(rLinha + 24, "R") = "PICADO"
                    Cells(rLinha + 24, "T") = CDate(DATA)
                    somaValores6 = somaValores6 + VALOR6
                    
                    Cells(rLinha + 28, "S") = Format(VALOR7, "###0.00")
                    Cells(rLinha + 28, "R") = "MOELA"
                    Cells(rLinha + 28, "T") = CDate(DATA)
                    somaValores7 = somaValores7 + VALOR7

                    Cells(rLinha + 32, "S") = Format(VALOR8, "###0.00")
                    Cells(rLinha + 32, "R") = "FIGADO"
                    Cells(rLinha + 32, "T") = CDate(DATA)
                    somaValores8 = somaValores8 + VALOR8
                    
                    Cells(rLinha + 36, "S") = Format(VALOR9, "###0.00")
                    Cells(rLinha + 36, "R") = "GALETO"
                    Cells(rLinha + 36, "T") = CDate(DATA)
                    somaValores9 = somaValores9 + VALOR9
                    
                    Cells(rLinha + 40, "S") = Format(VALOR10, "###0.00")
                    Cells(rLinha + 40, "R") = "MIUDO"
                    Cells(rLinha + 40, "T") = CDate(DATA)
                    somaValores10 = somaValores10 + VALOR10
                    
                    Cells(rLinha + 44, "S") = Format(VALOR11, "###0.00")
                    Cells(rLinha + 44, "R") = "FRENTE"
                    Cells(rLinha + 44, "T") = CDate(DATA)
                    somaValores11 = somaValores11 + VALOR11
                    
                    Cells(rLinha + 48, "S") = Format(VALOR12, "###0.00")
                    Cells(rLinha + 48, "R") = "FILÉ"
                    Cells(rLinha + 48, "T") = CDate(DATA)
                    somaValores12 = somaValores12 + VALOR12
                    
                    Cells(rLinha + 52, "S") = Format(VALOR13, "###0.00")
                    Cells(rLinha + 52, "R") = "BOBINA"
                    Cells(rLinha + 52, "T") = CDate(DATA)
                    somaValores13 = somaValores13 + VALOR13
                    
                    Cells(rLinha + 56, "S") = Format(VALOR14, "###0.00")
                    Cells(rLinha + 56, "R") = "MATRIZ"
                    Cells(rLinha + 56, "T") = CDate(DATA)
                    somaValores14 = somaValores14 + VALOR14

                      rLinha = rLinha + 1
                   
               End If
         
         End If
                  
        Next
        
        Cells(rLinha, "T") = valorcliente
        Cells(rLinha, "R") = "TOTAL (Kg):"
        Cells(rLinha, "S") = Format(somaValores, "STANDARD")
        Cells(rLinha + 1, "T") = Cells(rLinha, "S") * Cells(rLinha, "T")
        
        Cells(rLinha + 4, "T") = 5.5
        Cells(rLinha + 4, "R") = "TOTAL (Kg):"
        Cells(rLinha + 4, "S") = Format(somaValores1, "STANDARD")
        Cells(rLinha + 5, "T") = Cells(rLinha + 4, "S") * Cells(rLinha + 4, "T")

        Cells(rLinha + 8, "T") = 5.7
        Cells(rLinha + 8, "R") = "TOTAL (Kg):"
        Cells(rLinha + 8, "S") = Format(somaValores2, "STANDARD")
        Cells(rLinha + 9, "T") = Cells(rLinha + 8, "S") * Cells(rLinha + 8, "T")

        Cells(rLinha + 12, "T") = 7.9
        Cells(rLinha + 12, "R") = "TOTAL (Kg):"
        Cells(rLinha + 12, "S") = Format(somaValores3, "STANDARD")
        Cells(rLinha + 13, "T") = Cells(rLinha + 12, "S") * Cells(rLinha + 12, "T")

        Cells(rLinha + 16, "T") = 8
        Cells(rLinha + 16, "R") = "TOTAL (Kg):"
        Cells(rLinha + 16, "S") = Format(somaValores4, "STANDARD")
        Cells(rLinha + 17, "T") = Cells(rLinha + 16, "S") * Cells(rLinha + 16, "T")
                 
        Cells(rLinha + 20, "T") = 15
        Cells(rLinha + 20, "R") = "TOTAL (Kg):"
        Cells(rLinha + 20, "S") = Format(somaValores5, "STANDARD")
        Cells(rLinha + 21, "T") = Cells(rLinha + 20, "S") * Cells(rLinha + 20, "T")
  
        Cells(rLinha + 24, "T") = 3
        Cells(rLinha + 24, "R") = "TOTAL (Kg):"
        Cells(rLinha + 24, "S") = Format(somaValores6, "STANDARD")
        Cells(rLinha + 25, "T") = Cells(rLinha + 24, "S") * Cells(rLinha + 24, "T")

        Cells(rLinha + 28, "T") = 4
        Cells(rLinha + 28, "R") = "TOTAL (Kg):"
        Cells(rLinha + 28, "S") = Format(somaValores7, "STANDARD")
        Cells(rLinha + 29, "T") = Cells(rLinha + 28, "S") * Cells(rLinha + 28, "T")

        Cells(rLinha + 32, "T") = 3
        Cells(rLinha + 32, "R") = "TOTAL (Kg):"
        Cells(rLinha + 32, "S") = Format(somaValores8, "STANDARD")
        Cells(rLinha + 33, "T") = Cells(rLinha + 32, "S") * Cells(rLinha + 32, "T")

        Cells(rLinha + 36, "T") = 12
        Cells(rLinha + 36, "R") = "TOTAL (Kg):"
        Cells(rLinha + 36, "S") = Format(somaValores9, "STANDARD")
        Cells(rLinha + 37, "T") = Cells(rLinha + 36, "S") * Cells(rLinha + 36, "T")

        Cells(rLinha + 40, "T") = 1.5
        Cells(rLinha + 40, "R") = "TOTAL (Kg):"
        Cells(rLinha + 40, "S") = Format(somaValores10, "STANDARD")
        Cells(rLinha + 41, "T") = Cells(rLinha + 40, "S") * Cells(rLinha + 40, "T")

        Cells(rLinha + 44, "T") = 6.7
        Cells(rLinha + 44, "R") = "TOTAL (Kg):"
        Cells(rLinha + 44, "S") = Format(somaValores11, "STANDARD")
        Cells(rLinha + 45, "T") = Cells(rLinha + 44, "S") * Cells(rLinha + 44, "T")

        Cells(rLinha + 48, "T") = 12
        Cells(rLinha + 48, "R") = "TOTAL (Kg):"
        Cells(rLinha + 48, "S") = Format(somaValores12, "STANDARD")
        Cells(rLinha + 49, "T") = Cells(rLinha + 48, "S") * Cells(rLinha + 48, "T")

        Cells(rLinha + 52, "T") = 12
        Cells(rLinha + 52, "R") = "TOTAL (Kg):"
        Cells(rLinha + 52, "S") = Format(somaValores13, "STANDARD")
        Cells(rLinha + 53, "T") = Cells(rLinha + 52, "S") * Cells(rLinha + 52, "T")

        Cells(rLinha + 56, "T") = 6
        Cells(rLinha + 56, "R") = "TOTAL (Kg):"
        Cells(rLinha + 56, "S") = Format(somaValores14, "STANDARD")
        Cells(rLinha + 57, "T") = Cells(rLinha + 56, "S") * Cells(rLinha + 56, "T")

        
     End With
                      
         Cells(rLinha + 1, "S") = "TOTAL:"
         Cells(rLinha + 1, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 1, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 5, "S") = "TOTAL:"
         Cells(rLinha + 5, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 5, "T").Font.Color = RGB(255, 255, 255)

         Cells(rLinha + 9, "S") = "TOTAL:"
         Cells(rLinha + 9, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 9, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 13, "S") = "TOTAL:"
         Cells(rLinha + 13, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 13, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 17, "S") = "TOTAL:"
         Cells(rLinha + 17, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 17, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 21, "S") = "TOTAL:"
         Cells(rLinha + 21, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 21, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 25, "S") = "TOTAL:"
         Cells(rLinha + 25, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 25, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 29, "S") = "TOTAL:"
         Cells(rLinha + 29, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 29, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 33, "S") = "TOTAL:"
         Cells(rLinha + 33, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 33, "T").Font.Color = RGB(255, 255, 255)

         Cells(rLinha + 37, "S") = "TOTAL:"
         Cells(rLinha + 37, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 37, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 41, "S") = "TOTAL:"
         Cells(rLinha + 41, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 41, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 45, "S") = "TOTAL:"
         Cells(rLinha + 45, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 45, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 49, "S") = "TOTAL:"
         Cells(rLinha + 49, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 49, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 53, "S") = "TOTAL:"
         Cells(rLinha + 53, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 53, "T").Font.Color = RGB(255, 255, 255)
         
         Cells(rLinha + 57, "S") = "TOTAL:"
         Cells(rLinha + 57, "T").Interior.Color = RGB(0, 0, 0)
         Cells(rLinha + 57, "T").Font.Color = RGB(255, 255, 255)
         
End Function

ABAIXO TBM A IMAGEM DE COMO QUERO QUE FIQUE !
ATT.
Anexos
22.png
22.png (62.1 KiB) Exibido 2114 vezes


Responder