Como enviar list view para planilha vba

Fechado
edan3 Posts 2 Data de inscrição quarta 12 de março de 2014 Status Membro Última visita terça 18 de março de 2014 - 12 mar 2014 às 22:29
aaafelix Posts 1285 Data de inscrição sábado 10 de novembro de 2012 Status Contribuinte Última visita 27 de outubro de 2023 - 15 mar 2014 às 10:51
ola sou iniciante em vba e andei copiando uns codigos e editando formularios ate que
cheguei neste resultado. mas nao consico fazer os botoes de opção colocarem iformação na cedula e nem consigo passar do list view para planilha.

Option Explicit

Private Sub bt_cancelar_Click()
Unload Me
If ActiveCell = "" Then
ActiveCell.Offset(-1, 0).Select
End If
End Sub

Private Sub bt_gravar_Click()
desprotege
ActiveCell = txt_código.Value
ActiveCell.Offset(0, 1) = txt_solicitante.Value
ActiveCell.Offset(0, 2) = txt_setor.Text
ActiveCell.Offset(0, 3) = Textqnt.Value
ActiveCell.Offset(0, 4) = Textunid.Value
ActiveCell.Offset(0, 5) = Textprod.Value
ActiveCell.Offset(0, 6) = Textaplic.Value
If ActiveCell.Range(0, 7) = "" Then
OptionButton1.Value = True
ActiveCell.FormulaR1C1 = "APROVADO"
OptionButton2.Value = ""
ActiveCell.FormulaR1C1 = "AGUARDANDO"
OptionButton3.Value = "NEGADO"

ActiveCell.FormulaR1C1 = "NEGADO"
End If


If ActiveCell.FormulaR1C1 = "" Then
Range(0, 8).Select
OptionButton4.Value = ""
ActiveCell.FormulaR1C2 = "NORMAL"
OptionButton5.Value = True

ActiveCell.FormulaR1C2 = "URGENTE"
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With
Selection.Font.Bold = True
End If

'ActiveCell.Offset(0, 7) =
'= "Aprovado" Or "Aguardando" Or "Negado"
' ActiveCell.Offset(0, 8) = txt_obs.Value
ActiveCell.Offset(0, 9) = txt_datainclusão.Value
protege
ActiveCell.Offset(1, 0).Select
Unload Me
End Sub

Private Sub CommandButton1_Click()
If Me.Textqnt.Text = "" Then
Me.Textunid.Text = ""
Me.Textprod.Text = ""
Me.Textaplic.Text = ""
Else
End If



Me.ListBox1.AddItem Me.Textqnt.Text
Me.Textqnt.Text = ""
Me.ListBox1.AddItem Me.Textunid.Text
Me.Textunid.Text = ""
Me.ListBox1.AddItem Me.Textprod.Text
Me.Textprod.Text = ""
Me.ListBox1.AddItem Me.Textaplic.Text
Me.Textaplic.Text = ""

End Sub

Private Sub CommandButton3_Click()
Me.Label13.Caption = Me.ListBox1.ListCount & " Itens"
End Sub

Private Sub CommandButton2_Click()
If Me.ListBox1.ListCount = 0 Then
Else
Me.ListBox1.RemoveItem (Me.ListBox1.ListIndex)
End If
End Sub

Private Sub ListBox1_Click()
Me.Label12.Caption = Me.ListBox1.Text
End Sub


P

Private Sub txt_cliente_Change()

End Sub

Private Sub OptionButton1_Click()

End Sub

Private Sub OptionButton4_Click()

End Sub

Private Sub UserForm_initialize()
txt_datainclusão = Date
txt_código = valmax + 1
End Sub

Private Sub UserForm_Terminate()
If ActiveCell = "" Then
ActiveCell.Offset(-1, 0).Select
End If
End Sub



e ainda faltam botao de pesquisa e impressao da planilha
espero que consigam me ajudar


https://mega.co.nz/#!8s9lzQ6b!YUoMpGf66szE7dcI2fVlkBD_WzsL1pTNxF0XJ-oapss
ta ai o link da planilha é pro meu trabalho e nao to conseguindo

espero que alguem possa me ajudar.

1 Respostas

aaafelix Posts 1285 Data de inscrição sábado 10 de novembro de 2012 Status Contribuinte Última visita 27 de outubro de 2023 1.730
15 mar 2014 às 10:51
Editar esta macro em um modulo e associar a um botão na plan1

Sub GravaListBox()
'Grava os dados da Listbox1(5 colunas) da Plan1 na Plan2
'Na Plan2 - Grava nas colunas A a E a partir da Linha 2
' antes limpando todos dados gravados anteriormente
Dim Ctd As Integer 'contador
Dim Ctd1 As Integer
Dim Nlin_LB As Integer 'Num linhas da ListBox
Dim Nlin_PL As Long 'Num linha para Limpar/gravar
Dim V_Plan2 As Worksheet
Dim V_LBox As OLEObject

Set V_Plan2 = Worksheets("Plan2")
Set V_LBox = Worksheets("Plan1").OLEObjects("ListBox1")

Nlin_LB = V_LBox.Object.ListCount - 1

If Nlin_LB >= 0 Then
'Verifica ultima linha com dados na Plan2
Nlin_PL = V_Plan2.Cells(V_Plan2.Rows.Count, 1).End(xlUp).Row
'Limpa Plan2
V_Plan2.Range("A2:E" & Nlin_PL).ClearContents
Nlin_PL = 2
'Loop grava listbox na planilha
For Ctd = 0 To Nlin_LB 'ctd numero de linhas da listbox
For Ctd1 = 0 To 4 'ctd1 numero de colunas da listbox e Plan2
V_Plan2.Cells(Nlin_PL, Ctd1 + 1).Value = V_LBox.Object.List(Ctd, Ctd1)
Next
Nlin_PL = Nlin_PL + 1
Next
MsgBox "Conteudo da Listbox1 gravados na Plan2 com sucesso"
Else
MsgBox "ListBox vazia", vbOKOnly, "ATENÇÃO"
End If
End Sub

Abraços, Almir Felix.
0

Assine nossa newsletter!

Assine nossa newsletter!
Junte-se à comunidade