Sei sulla pagina 1di 16

'Option Explicit Private valor_pesquisado As String Private Sub btn_cadastro_Click() Dim cod As Double Dim quant As Double Dim

valunit As Currency Dim valtot As Currency cod = txt_codigo quant = txt_quantidade valunit = txt_valor_unitario Sheets("estoque").Select ' seleciona a guia estoque Range("A1048576").Select ' seleciona a ltima linha da culuna A Selection.End(xlUp).Select ' excuta o comando equivalente a pressionar juntas as teclas CLTR + UP (seta para cima) para localizar a primeira clula com conteudo ActiveCell.Offset(1, 0).Select 'desce uma unidade na vertical (uma linha) e seleciona a mesma ActiveCell = cod ' armazena na clula ativa o valor da varivel registro ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = txt_produto ' armazena a varivel data na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = txt_unidade ' armazena a varivel data na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = quant ' armazena a varivel data na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = valunit ' armazena a varivel data na cluma ativa

ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell.FormulaR1C1 = "=RC[-1]*RC[-2]" ' aciona a frmula txt_codigo = "" txt_produto = "" txt_unidade = "" txt_quantidade = "" txt_valor_unitario = "" Call carrega_listaprodutos End Sub Private Sub lst_produtos_Click() Dim valor_lista As Integer Dim selecao As Integer selecao = lst_produtos.ListIndex If lst_produtos.List(selecao, 0) = "" Then Exit Sub Else valor_lista = lst_produtos.List(selecao, 0) End If txt_codigo = valor_lista txt_codigo.SetFocus If opt_entrada = True Or opt_saida = True Then txt_movimento.SetFocus ElseIf opt_entrada = False And opt_saida = False And opt_novo = False Then Exit Sub Else txt_produto.SetFocus End If End Sub Private Sub opt_novo_Click()

txt_codigo = "" txt_produto = "" txt_unidade = "" txt_quantidade = "" txt_valor_unitario = "" lst_fluxo.Clear btn_atualiza.Enabled = False btn_busca.Enabled = False btn_cadastro.Enabled = True btn_apaga.Enabled = True

End With With txt_nfe .Enabled = False .BackStyle = fmBackStyleTransparent .BorderStyle = fmBorderStyleSingle .SpecialEffect = fmSpecialEffectFlat End With Label7.Enabled = False Label8.Enabled = False Label30.Enabled = False txt_codigo.SetFocus

txt_codigo.Enabled = True txt_produto.Enabled = True txt_produto.Locked = False txt_unidade.Enabled = True txt_unidade.Locked = False txt_quantidade.Enabled = True txt_quantidade.BackStyle = fmBackStyleOpaque txt_quantidade.BorderStyle = fmBorderStyleNone txt_quantidade.SpecialEffect = fmSpecialEffectSunken With txt_valor_unitario .Enabled = True .BackStyle = fmBackStyleOpaque .BorderStyle = fmBorderStyleNone .SpecialEffect = fmSpecialEffectSunken End With With txt_movimento .Enabled = False .BackStyle = fmBackStyleTransparent .BorderStyle = fmBorderStyleSingle .SpecialEffect = fmSpecialEffectFlat

End Sub Private Sub txt_busca_Change() valor_pesquisado = txt_busca.Text If txt_codigo = "" Then Call buscar_valores_sem_codigo Else Call buscar_valores Call somar_entradas_saidas_com_codigo End If End Sub Private Sub buscar_valores() Dim guia As Worksheet Dim linha As Integer Dim coluna As Integer Dim linhalistbox As Integer Dim valor_celula As String Dim conta_registros As Integer Dim codigo As Integer Set guia = ThisWorkbook.Worksheets(2) codigo = txt_codigo

linha = 2 coluna = 3 linhalistbox = 0 conta_registros = 0 lst_fluxo.Clear With guia While .Cells(linha, coluna).Value <> Empty valor_celula = .Cells(linha, coluna).Value If UCase(Left(valor_celula, Len(valor_pesquisado))) = UCase(valor_pesquisado) Then

End If

End If linha = linha + 1 Wend End With lbl_lista = conta_registros End Sub

Private Sub buscar_valores_sem_codigo() Dim guia As Worksheet

If Sheets("Fluxo estoque").Cells(linha, 6) = codigo Then With UserForm1.lst_fluxo .AddItem .List(linhalistbox, 0) = Sheets("Fluxo estoque").Cells(linha, 1) .List(linhalistbox, 1) = Sheets("Fluxo estoque").Cells(linha, 3) .List(linhalistbox, 2) = Sheets("Fluxo estoque").Cells(linha, 4) .List(linhalistbox, 3) = Sheets("Fluxo estoque").Cells(linha, 5) .List(linhalistbox, 4) = Sheets("Fluxo estoque").Cells(linha, 2) .List(linhalistbox, 5) = Sheets("Fluxo estoque").Cells(linha, 9) .List(linhalistbox, 6) = Sheets("Fluxo estoque").Cells(linha, 10) .List(linhalistbox, 7) = Sheets("Fluxo estoque").Cells(linha, 11) linhalistbox = linhalistbox + 1

Dim linha As Integer Dim coluna As Integer Dim linhalistbox As Integer Dim valor_celula As String Dim conta_registros As Integer

Set guia = ThisWorkbook.Worksheets(2) linha = 2 coluna = 3 linhalistbox = 0 conta_registros = 0 lst_fluxo.Clear With guia While .Cells(linha, coluna).Value <> Empty valor_celula = .Cells(linha, coluna).Value If UCase(Left(valor_celula, Len(valor_pesquisado))) = UCase(valor_pesquisado) Then With UserForm1.lst_fluxo

conta_registros = conta_registros + 1 .AddItem End With Else .List(linhalistbox, 0) = Sheets("Fluxo estoque").Cells(linha, 1)

.List(linhalistbox, 1) = Sheets("Fluxo estoque").Cells(linha, 3) .List(linhalistbox, 2) = Sheets("Fluxo estoque").Cells(linha, 4) .List(linhalistbox, 3) = Sheets("Fluxo estoque").Cells(linha, 5) .List(linhalistbox, 4) = Sheets("Fluxo estoque").Cells(linha, 2) .List(linhalistbox, 5) = Sheets("Fluxo estoque").Cells(linha, 9) .List(linhalistbox, 6) = Sheets("Fluxo estoque").Cells(linha, 10) .List(linhalistbox, 7) = Sheets("Fluxo estoque").Cells(linha, 11) linhalistbox = linhalistbox + 1 conta_registros = conta_registros + 1 End With

linha = 2 codigo = txt_codigo quantidade = txt_quantidade valor = txt_valor_unitario If opt_entrada = False And opt_saida = False Then MsgBox ("Favor selecione - Entrada ou Sada") ' mostra a mensagem Exit Sub 'encerra o procedimento End If ' encerra o teste lgico If txt_codigo = "" Then 'se a caixa de texto for vazia ento MsgBox ("Favor preencha o cdigo") ' mostra a mensagem txt_codigo.SetFocus 'd foco novamente na caixa de texto Exit Sub 'encerra o procedimento End If ' encerra o teste lgico

End If linha = linha + 1 Wend End With lbl_lista = conta_registros End Sub Private Sub btn_atualiza_Click() Dim codigo As Integer Dim quantidade As Double Dim valor As Currency If txt_codigo = "" Or txt_movimento = "" Then MsgBox ("Falta o preenchimento de algum campo... favor verificar") txt_codigo.SetFocus Exit Sub Else 'endif vai para o final do cdigo

If txt_movimento = "" Then 'se a caixa de texto for vazia ento MsgBox ("Favor preencha a quantidade") ' mostra a mensagem txt_movimento.SetFocus 'd foco novamente na caixa de texto Exit Sub 'encerra o procedimento End If ' encerra o teste lgico If opt_entrada = True Then Sheets("estoque").Select Do Until Sheets("estoque").Cells(linha, 1) = "" 'condico para localizar o cdigo If Sheets("estoque").Cells(linha, 1) = codigo Then Sheets("estoque").Cells(linha, 1).Select ActiveCell.Offset(0, 1).Select ActiveCell = txt_produto ActiveCell.Offset(0, 1).Select

ActiveCell = txt_unidade ActiveCell.Offset(0, 1).Select ActiveCell = quantidade + txt_movimento ActiveCell.Offset(0, 1).Select ActiveCell = valor ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=RC[-2]*RC[-1]" MsgBox ("Dados alterandos com sucesso!!!") End If linha = linha + 1 Loop Else ' caso no estaja selecionado a entrada ser dada a sada Sheets("estoque").Select Do Until Sheets("estoque").Cells(linha, 1) = "" 'condico para localizar o cdigo If Sheets("estoque").Cells(linha, 1) = codigo Then Sheets("estoque").Cells(linha, 1).Select ActiveCell.Offset(0, 1).Select ActiveCell = txt_produto ActiveCell.Offset(0, 1).Select ActiveCell = txt_unidade ActiveCell.Offset(0, 1).Select ActiveCell = quantidade - txt_movimento ActiveCell.Offset(0, 1).Select ActiveCell = valor

Loop End If Dim data_movimento As Date Dim codigo_mov As Integer Dim id As Integer Dim quantidade_mov As Integer Dim unitario As Currency Dim total As Currency data_movimento = Date id = txt_id codigo_mov = txt_codigo quantidade_mov = txt_movimento unitario = txt_valor_unitario total = txt_valor_movimento Sheets("Fluxo estoque").Select ' seleciona a guia Fluxo Range("A1048576").Select ' seleciona a ltima linha da culuna A Selection.End(xlUp).Select ' excuta o comando equivalente a pressionar juntas as teclas CLTR + UP (seta para cima) para localizar a primeira clula com conteudo ActiveCell.Offset(1, 0).Select 'desce uma unidade na vertical (uma linha) e seleciona a mesma ActiveCell = id ' armazena na clula ativa o valor da varivel registro ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma If opt_entrada = True Then ' se o boto de opo entrada estiver selecionado ento ActiveCell = "Entrada" ' a clula ativa recebera o valor "Entrada" Else ' caso contrario ActiveCell = "Sada" ' a clula ativa receber o valor de "Sada End If 'fim do teste lgico

ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=RC[-2]*RC[-1]" MsgBox ("Dados alterandos com sucesso!!!") End If linha = linha + 1

ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = data_movimento ' armazena a varivel na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell.FormulaR1C1 = "=MONTH(RC[-1])" ' aciona a frmula =mes(clula uma unidade a esquerda) para mostrar o mes do movimento ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell.FormulaR1C1 = "=YEAR(RC[-2])" ' aciona a frmula =ano(clula uma unidade a esquerda) para mostrar o ano do movimento ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = codigo_mov ' armazena a varivel na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = txt_produto ' armazena a varivel na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = txt_unidade ' armazena a varivel na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = quantidade_mov ' armazena a varivel na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = unitario ' armazena a varivel na cluma ativa ActiveCell.Offset(0, 1).Select 'desloca o cursor uma unidade para direita, uma coluna e seleciona a mesma ActiveCell = total ' armazena a varivel na cluma ativa Sheets("estoque").Select Do Until Sheets("estoque").Cells(linha, 1) = "" 'condico para localizar o cdigo If Sheets("estoque").Cells(linha, 1) = codigo Then Dim codigo As Integer ActiveCell = txt_nfe ' armazena a varivel na cluma ativa Call txt_codigo_AfterUpdate Call UserForm_Initialize txt_movimento = "" txt_valor_movimento = "" txt_nfe = "" txt_codigo = "" txt_produto = "" txt_unidade = ""

opt_entrada = False opt_saida = False txt_codigo.SetFocus End If End Sub Private Sub btn_busca_Click() UserForm4.Show End Sub Private Sub btn_apaga_Click()

linha = 2 codigo = txt_codigo

Sheets("estoque").Cells(linha, 1).Select Dim resposta As String 'cria a varivel resposta resposta = MsgBox("O registro ser excludo. Confirma a excluso?", vbYesNo) 'cria a mensagem para determinar qual ao ser executada If resposta = vbYes Then ' se a resposta for sim ento 'comando para deletar toda a linha ActiveCell.Rows("1:1").EntireRow.Select Selection.Delete Shift:=xlUp ActiveCell.Select 'limpa todos os campos do formulrio txt_codigo = "" txt_produto = "" txt_unidade = "" txt_quantidade = "" txt_valor_unitario = "" txt_total = "" MsgBox ("Registro excludo com sucesso!!!") Else End If End If linha = linha + 1 Loop txt_codigo.SetFocus End Sub Private Sub opt_entrada_Click()

btn_apaga.Enabled = False txt_busca.Enabled = True txt_nfe.Enabled = True

txt_codigo.Enabled = True txt_produto.Enabled = False txt_produto.Locked = True

txt_unidade.Enabled = False txt_unidade.Locked = True

txt_quantidade.Enabled = False txt_quantidade.BackStyle = fmBackStyleTransparent txt_quantidade.BorderStyle = fmBorderStyleSingle txt_quantidade.SpecialEffect = fmSpecialEffectFlat

With txt_valor_unitario .Enabled = False .BackStyle = fmBackStyleTransparent .BorderStyle = fmBorderStyleSingle .SpecialEffect = fmSpecialEffectFlat End With

With txt_movimento .Enabled = True .BackStyle = fmBackStyleOpaque .BorderStyle = fmBorderStyleNone

lst_produtos.Locked = False btn_atualiza.Enabled = True btn_busca.Enabled = True btn_cadastro.Enabled = False

.SpecialEffect = fmSpecialEffectSunken End With

With txt_nfe

.Enabled = True .BackStyle = fmBackStyleOpaque .BorderStyle = fmBorderStyleNone .SpecialEffect = fmSpecialEffectSunken End With

txt_quantidade.Enabled = False txt_quantidade.BackStyle = fmBackStyleTransparent txt_quantidade.BorderStyle = fmBorderStyleSingle txt_quantidade.SpecialEffect = fmSpecialEffectFlat

With txt_valor_unitario Label7.Enabled = True Label8.Enabled = True Label30.Enabled = True .Enabled = False .BackStyle = fmBackStyleTransparent .BorderStyle = fmBorderStyleSingle .SpecialEffect = fmSpecialEffectFlat txt_codigo.SetFocus End With

End Sub

With txt_movimento .Enabled = True

Private Sub opt_saida_Click()

.BackStyle = fmBackStyleOpaque .BorderStyle = fmBorderStyleNone

lst_produtos.Locked = False btn_atualiza.Enabled = True btn_busca.Enabled = True btn_cadastro.Enabled = False btn_apaga.Enabled = False txt_busca.Enabled = True txt_nfe.Enabled = True

.SpecialEffect = fmSpecialEffectSunken End With

With txt_nfe .Enabled = True .BackStyle = fmBackStyleOpaque .BorderStyle = fmBorderStyleNone .SpecialEffect = fmSpecialEffectSunken

txt_codigo.Enabled = True txt_produto.Enabled = False txt_produto.Locked = True

End With

Label7.Enabled = True Label8.Enabled = True

txt_unidade.Enabled = False txt_unidade.Locked = True

Label30.Enabled = True

txt_codigo.SetFocus

End Sub

Loop

Private Sub txt_codigo_AfterUpdate() Else If txt_codigo = "" Then Exit Sub Dim intervalo As Range Dim texto As String Else If opt_novo = True Then Dim codigo As Integer Dim pesquisa2 As Double Dim mensagem 'verifica se o cdigo j existe codigo = txt_codigo Dim cod As Integer Dim linha As Integer Sheets("estoque").Select Set intervalo = Range("A2:F500")

On Error GoTo Erro linha = 2 cod = txt_codigo pesquisa = Application.WorksheetFunction.VLookup(codigo, intervalo, 2, False) pesquisa1 = Application.WorksheetFunction.VLookup(codigo, intervalo, 3, False) pesquisa2 = Application.WorksheetFunction.VLookup(codigo, intervalo, 4, False) pesquisa3 = Application.WorksheetFunction.VLookup(codigo, intervalo, 5, False) pesquisa4 = Application.WorksheetFunction.VLookup(codigo, intervalo, 6, False)

Do Until Sheets("estoque").Cells(linha, 1) = ""

If Sheets("estoque").Cells(linha, 1) = cod Then MsgBox ("Cdigo j cadastrado..") txt_codigo = "" Exit Sub

Else 'continua o cdigo End If linha = linha + 1

txt_produto = pesquisa

txt_unidade = pesquisa1 txt_quantidade = pesquisa2 txt_valor_unitario = pesquisa3 txt_total = pesquisa4

lst_fluxo.Clear lista = txt_codigo linha = 2 linhalistbox = 0 conta_lista = 0

txt_valor_unitario = Format(txt_valor_unitario, "R$ #,##0.00") txt_total = Format(txt_total, "R$ #,##0.00")

Sheets("Fluxo estoque").Select Do Until Sheets("Fluxo estoque").Cells(linha, 1) = "" If Sheets("Fluxo estoque").Cells(linha, 6) = lista Then

Call carrega_lista Call somar_entradas_saidas_com_codigo

With lst_fluxo .AddItem .List(linhalistbox, 0) = Sheets("Fluxo estoque").Cells(linha, 1) .List(linhalistbox, 1) = Sheets("Fluxo estoque").Cells(linha, 3) .List(linhalistbox, 2) = Sheets("Fluxo estoque").Cells(linha, 4)

End If

Exit Sub Erro: texto = "No foi localizado nenhum valor correspondente ao cdigo..." mensagem = MsgBox(texto, vbOKOnly + vbInformation) End If

.List(linhalistbox, 3) = Sheets("Fluxo estoque").Cells(linha, 5) .List(linhalistbox, 4) = Sheets("Fluxo estoque").Cells(linha, 2) .List(linhalistbox, 5) = Sheets("Fluxo estoque").Cells(linha, 9) .List(linhalistbox, 6) = Sheets("Fluxo estoque").Cells(linha, 10) .List(linhalistbox, 7) = Sheets("Fluxo estoque").Cells(linha, 11) End With

End Sub

Sub carrega_lista()

'carrega dados de entrada e sada de estoque

linhalistbox = linhalistbox + 1 conta_lista = conta_lista + 1

Dim lista As Double Else

End If

txt_movimento = "" Exit Sub

linha = linha + 1 Else Loop If txt_movimento = "" Then lbl_lista = conta_lista Exit Sub

Else End Sub valor_movimento = txt_movimento * txt_valor_unitario txt_valor_movimento = valor_movimento Private Sub txt_movimento_AfterUpdate() txt_valor_movimento = Format(txt_valor_movimento, "R$ #,##0.00") End If Dim valor_movimento As Currency Dim negativo As Double Dim movimento As Double Dim quantidade_estoque As Double End If If txt_movimento = "" Then Exit Sub Else End Sub Private Sub txt_valor_unitario_AfterUpdate() End If

movimento = txt_movimento quantidade_estoque = txt_quantidade

txt_total = txt_valor_unitario * txt_quantidade

End Sub If opt_saida = True And movimento > quantidade_estoque Then

negativo = movimento - quantidade_estoque MsgBox ("O estoque ficar negativo em " & negativo & " Unidades") Private Sub UserForm_Initialize()

linha = 2 Dim linha As Integer Dim contador As Integer linhalistbox = 0 conta_lista = 0

linha = 2 'atribuindo valor 2 a varivel linha equivalente a linha 2 inicio da contagem dos dados contador = 0 'contador comea em 0

Sheets("Fluxo estoque").Select Do Until Sheets("Fluxo estoque").Cells(linha, 1) = ""

With lst_fluxo Do Until Sheets("Fluxo estoque").Cells(linha, 1) = "" 'Executa o looping at encontrar uma clula vazia na guia Fluxo, valor da linha determinada pela varivel e coluna 1 ou A If Sheets("Fluxo estoque").Cells(linha, 1) > contador Then 'Se o valor da clula for maior que o valor da varivel contador ele ira executar a ao contador = contador + 1 'ao de adicionar uma unidade a varivel contador linha = linha + 1 'ao de adicionar uma unidade a variavel linha para dar continuidade ao looping Else ' caso no seja satisfeita a condio IF no ser feita nenhuma ao, por isso no h nenhum comando apos o ELSE End If 'encerramento dao teste lgico Loop ' encerramento do looping .AddItem .List(linhalistbox, 0) = Sheets("Fluxo estoque").Cells(linha, 1) .List(linhalistbox, 1) = Sheets("Fluxo estoque").Cells(linha, 3) .List(linhalistbox, 2) = Sheets("Fluxo estoque").Cells(linha, 4) .List(linhalistbox, 3) = Sheets("Fluxo estoque").Cells(linha, 5) .List(linhalistbox, 4) = Sheets("Fluxo estoque").Cells(linha, 2) .List(linhalistbox, 5) = Sheets("Fluxo estoque").Cells(linha, 9) .List(linhalistbox, 6) = Sheets("Fluxo estoque").Cells(linha, 10) .List(linhalistbox, 7) = Sheets("Fluxo estoque").Cells(linha, 11) End With

contador = contador + 1 'quando o looping ou lao for terminado ele ter encontrado o maior valor da coluna 1 por isso adicionanos uma unidade para que a caixa de texto receba esse valor para o prximo lanamento

linhalistbox = linhalistbox + 1 txt_id = contador ' atribuimos a caixa de texto o valor da varivel contador conta_lista = conta_lista + 1

linha = linha + 1

'carrega dados de entrada e sada de estoque

Loop

lst_fluxo.Clear

lbl_lista = conta_lista

Loop

lbl_produtos = conta_produtos

Call carrega_listaprodutos Call conta_itens Call soma_valor_itens

End Sub

Sub conta_itens()

'soma itens em estoque End Sub Sub carrega_listaprodutos() Dim acumulador As Double Dim linha As Integer Dim conta_estoque As Double 'carrega itens na listbox produtos linha = 2 linhalistbox = 0 conta_produtos = 0 conta_estoque = 0 soma_valor_estoque = 0 Do Until Sheets("estoque").Cells(linha, 1) = "" conta_estoque = 0 linha = 2 acumulador = 0

acumulador = Sheets("estoque").Cells(linha, 4) Do Until Sheets("estoque").Cells(linha, 1) = "" linha = linha + 1 conta_estoque = conta_estoque + acumulador With lst_produtos .AddItem .List(linhalistbox, 0) = Sheets("estoque").Cells(linha, 1) .List(linhalistbox, 1) = Sheets("estoque").Cells(linha, 2) linhalistbox = linhalistbox + 1 End With linha = linha + 1 conta_produtos = conta_produtos + 1 'soma valor total do estoque Sub soma_valor_itens() lbl_itens_estoque = conta_estoque Loop

End Sub

Dim acumulador As Currency Dim linha As Integer Dim soma_estoque As Currency acumulador_entrada = 0 acumulador_saida = 0 soma_entrada = 0 soma_estoque = 0 linha = 2 acumulador = 0 soma_saida = 0 linha = 2 acumulador = 0 'cod = txt_codigo Do Until Sheets("estoque").Cells(linha, 1) = "" Do Until Sheets("Fluxo estoque").Cells(linha, 1) = "" acumulador = Sheets("estoque").Cells(linha, 6) linha = linha + 1 soma_estoque = soma_estoque + acumulador Loop 'If Sheets("Fluxo estoque").Cells(linha, 6) = cod Then If Sheets("Fluxo estoque").Cells(linha, 2) = "Entrada" Then acumulador_entrada = Sheets("Fluxo estoque").Cells(linha, 11) lbl_valor_estoque = soma_estoque lbl_valor_estoque = Format(lbl_valor_estoque, "R$ #,##0.00") Else acumulador_saida = Sheets("Fluxo estoque").Cells(linha, 11) End If End Sub soma_estoque = soma_estoque + acumulador soma_entrada = soma_entrada + acumulador_entrada Sub somar_entradas_saidas() soma_saida = soma_saida + acumulador_saida acumulador_entrada = 0 'soma valores de entrada e saida acumulador_saida = 0

Dim movimento As String Dim acumulador_entrada As Double Dim acumulador_saida As Double Dim soma_entrada As Currency Dim soma_saida As Currency 'Dim cod As Integer

'Else 'End If

linha = linha + 1 Loop

'lbl_valor_estoque = soma_estoque 'lbl_valor_estoque = Format(lbl_valor_estoque, "R$ #,##0.00") End Sub

lbl_valor_saidas = soma_saida lbl_valor_saidas = Format(lbl_valor_saidas, "R$ #,##0.00")

Sub somar_entradas_saidas_com_codigo()

'soma valores de entrada e saida

lbl_valor_entradas = soma_entrada lbl_valor_entradas = Format(lbl_valor_entradas, "R$ #,##0.00")

Dim movimento As String Dim acumulador_entrada As Double Dim acumulador_saida As Double Dim soma_entrada As Currency Dim soma_saida As Currency Dim cod As Integer

End Sub Private Sub CommandButton1_Click() acumulador_entrada = 0 acumulador_saida = 0 soma_entrada = 0 Call UserForm_Initialize Call somar_entradas_saidas soma_saida = 0 linha = 2 acumulador = 0 txt_codigo = "" txt_produto = "" txt_unidade = "" txt_quantidade = "" txt_valor_unitario = "" txt_total = "" opt_entrada = False opt_saida = False opt_novo = False If Sheets("Fluxo estoque").Cells(linha, 6) = cod Then If Sheets("Fluxo estoque").Cells(linha, 2) = "Entrada" Then acumulador_entrada = Sheets("Fluxo estoque").Cells(linha, 11) Else Do Until Sheets("Fluxo estoque").Cells(linha, 1) = "" cod = txt_codigo

acumulador_saida = Sheets("Fluxo estoque").Cells(linha, 11) End If

soma_estoque = soma_estoque + acumulador soma_entrada = soma_entrada + acumulador_entrada soma_saida = soma_saida + acumulador_saida acumulador_entrada = 0 acumulador_saida = 0

Else End If

linha = linha + 1 Loop

'lbl_valor_estoque = soma_estoque 'lbl_valor_estoque = Format(lbl_valor_estoque, "R$ #,##0.00")

lbl_valor_saidas = soma_saida lbl_valor_saidas = Format(lbl_valor_saidas, "R$ #,##0.00")

lbl_valor_entradas = soma_entrada lbl_valor_entradas = Format(lbl_valor_entradas, "R$ #,##0.00")

End Sub

Potrebbero piacerti anche