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

Botão alterar

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
djalmaM
Acabou de chegar
Acabou de chegar
Mensagens: 4
Registrado em: Qua Ago 15, 2018 11:35 am

Botão alterar

Mensagem por djalmaM »

Boa tarde para todos, soou novato em excel vba, estou fazendo um banco de dados, consegui colocar o batão de cadastro de produtos mas não consegui de forma alguma colocar para funcionar o botão alterar. algué pode me ajudar? vou colocar o arquivo em anexo.

não consigo anexar o arquivo do excel, mas vou colocar o codigo que usei para criar o formulario.


Public GeralResultados As Variant

Private Sub btnalterar_Click()
linha = Sheets("Estoque").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row


Planilha2.Cells(linha, 1).Value = Me.TextBox1.Text
Planilha2.Cells(linha, 2).Value = Me.TextBox2.Text
'Planilha2.Cells(linha, 3).Value = Me.TextBox3.Value
'Planilha2.Cells(linha, 4).Value = Me.TextBox4.Value
'Planilha2.Cells(linha, 5).Value = Me.TextBox5.Value
'Planilha2.Cells(linha, 6).Value = Me.TextBox6.Value
'Planilha2.Cells(linha, 11).Value = Me.TextBox7.Value
'Planilha2.Cells(linha, 12).Value = Me.TextBox8.Value


Me.TextBox1.Value = Null
Me.TextBox2.Value = Null
'Me.TextBox3.Value = Null
'Me.TextBox4.Value = Null
'Me.TextBox5.Value = Null
'Me.TextBox6.Value = Null
'Me.TextBox7.Value = Null
'Me.TextBox8.Value = Null

End Sub

Private Sub btncadastrar_Click()
linha = Sheets("Estoque").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row

Planilha2.Cells(linha, 1).Value = Me.TextBox1.Value
Planilha2.Cells(linha, 2).Value = Me.TextBox2.Value
Planilha2.Cells(linha, 3).Value = Me.TextBox3.Value
Planilha2.Cells(linha, 4).Value = Me.TextBox4.Value
Planilha2.Cells(linha, 5).Value = Me.TextBox5.Value
Planilha2.Cells(linha, 6).Value = Me.TextBox6.Value
Planilha2.Cells(linha, 11).Value = Me.TextBox7.Value
Planilha2.Cells(linha, 12).Value = Me.TextBox8.Value


Me.TextBox1.Value = Null
Me.TextBox2.Value = Null
Me.TextBox3.Value = Null
Me.TextBox4.Value = Null
Me.TextBox5.Value = Null
Me.TextBox6.Value = Null
Me.TextBox7.Value = Null
Me.TextBox8.Value = Null

End Sub

Private Sub BTNPESQUISARESTOQUE_Click()
If Me.TextBox9.Text = "" Then
MsgBox ("Digite o que você está procurando!"), vbInformation, "LDVENDAS 2.0"
Else
Call PesquisaPersonalizada(Me.TextBox9.Text)
End If
End Sub
Private Sub SpinButton1_Change()
Dim linha As Long
Dim Total As Long

Total = Me.SpinButton1.Max + 1
linha = GeralResultados(Me.SpinButton1.Value)

Me.LabelCONTADOR.Caption = Me.SpinButton1.Value + 1 & " de " & Total

Me.TextBox1.Text = Planilha2.Cells(linha, 1).Value
Me.TextBox2.Text = Planilha2.Cells(linha, 2).Value
Me.TextBox3.Text = Planilha2.Cells(linha, 3).Value
Me.TextBox4.Text = Planilha2.Cells(linha, 4).Value
Me.TextBox5.Text = Planilha2.Cells(linha, 5).Value
Me.TextBox6.Text = Planilha2.Cells(linha, 6).Value
Me.TextBox7.Text = Planilha2.Cells(linha, 11).Value
Me.TextBox8.Text = Planilha2.Cells(linha, 12).Value
End Sub
Private Sub PesquisaPersonalizada(ByVal Pesquisado As String)
Dim Pesquisa As Range
Dim Primeira As String
Dim Resultado As String

Set Pesquisa = Planilha2.Cells.Find(What:=Pesquisado, After:=Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not Pesquisa Is Nothing Then
Primeira = Pesquisa.Address
Resultado = Pesquisa.Row

Do
Set Pesquisa = Planilha2.Cells.FindNext(After:=Pesquisa)
If Not Pesquisa.Address Like Primeira Then
Resultado = Resultado & ";" & Pesquisa.Row
End If
Loop Until Pesquisa.Address Like Primeira

GeralResultados = Split(Resultado, ";")

Me.SpinButton1.Max = UBound(GeralResultados)


Me.SpinButton1.Enabled = True

Me.LabelCONTADOR.Caption = "1 de " & UBound(GeralResultados) + 1
Me.TextBox1.Text = Planilha2.Cells(GeralResultados(0), 1).Value
Me.TextBox2.Text = Planilha2.Cells(GeralResultados(0), 2).Value
Me.TextBox3.Text = Planilha2.Cells(GeralResultados(0), 3).Value
Me.TextBox4.Text = Planilha2.Cells(GeralResultados(0), 4).Value
Me.TextBox5.Text = Planilha2.Cells(GeralResultados(0), 5).Value
Me.TextBox6.Text = Planilha2.Cells(GeralResultados(0), 6).Value
Me.TextBox7.Text = Planilha2.Cells(GeralResultados(0), 11).Value
Me.TextBox8.Text = Planilha2.Cells(GeralResultados(0), 12).Value

Else
Me.SpinButton1.Enabled = False
Me.LabelCONTADOR.Caption = ""
Me.TextBox1.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.TextBox5.Text = ""
Me.TextBox6.Text = ""
Me.TextBox7.Text = ""
Me.TextBox8.Text = ""
MsgBox ("Nenhum resultado para '" & Pesquisado & "' foi encontrado."), vbInformation, "LDVENDAS 2.0."
End If
End Sub
Private Sub UserForm_Initialize()
Me.TextBox1.Enabled = True
Me.TextBox2.Enabled = True
Me.TextBox3.Enabled = True
Me.TextBox4.Enabled = True
Me.TextBox5.Enabled = True
Me.TextBox6.Enabled = True
Me.TextBox7.Enabled = True
Me.TextBox8.Enabled = True

Me.SpinButton1.Enabled = False
Me.LabelCONTADOR.Caption = " "
End Sub

Agora si consegui enviar o anexo.
LDVENDAS 2.0 -para forum.rar
(30.45 KiB) Baixado 230 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.


Avatar do usuário
Reinaldo
Jedi
Jedi
Mensagens: 1537
Registrado em: Sex Ago 01, 2014 4:09 pm
Localização: Garça - SP / SCS - SP

Re: Botão alterar

Mensagem por Reinaldo »

Veja se atende
LDVENDAS 2.0 -para forum.xlsm.zip
(26.94 KiB) Baixado 310 vezes


djalmaM
Acabou de chegar
Acabou de chegar
Mensagens: 4
Registrado em: Qua Ago 15, 2018 11:35 am

Re: Botão alterar

Mensagem por djalmaM »

Atendeu sim. estou muito agradecido mesmo, esta foi uma ajuda muito valorosa.Perfeito.
você pode me explicar a lógica para eu compreender?


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.


Responder