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

Listbox - Retorno de Valor de outra coluna

Esclarecimentos e dúvidas sob o Modelo de Aplicativo de Cadastro em VBA no Microsoft Excel publicado no site e blog http://www.tomasvasquez.com.br
chook
Colaborador
Colaborador
Mensagens: 13
Registrado em: Qua Mar 14, 2012 9:19 am

Listbox - Retorno de Valor de outra coluna

Mensagem por chook »

Bom dia,

estou com um listbox com 4 colunas, quero que retorne o valor da 3 coluna, sabendo que o BoundColumn=1

A linha que estou querendo que retorne o 3 valor da coluna está em negrito.

ActiveCell.Offset(0, 6).Value = Val(ListBox2.List(i))

Segue o código para melhor visualização:

Código: Selecionar todos

Private Sub CommandButton3_Click()
Dim i, j, UltimaLinha As Integer
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8

    For i = 0 To ListBox2.ListCount - 1
        If ListBox2.List(i) = True Then
                Sheets("Contas_Pagar").Activate 'Seleciona a planilha Banco
                Range("3:3").Select 'Seleciona a Linha 2 para inserção de nova linha
                Selection.Insert Shift:=xlDown 'Insere uma linha e coloca o banco para baixo
                Range("A3").Select 'Seleciona a primeira celula da base para inserção de dados

                ActiveCell.Value = Range("A4").Value + 1
                ActiveCell.Offset(0, 1).Value = "GRAFICA E EDITORA REVENDA PRINT LTDA"
                ActiveCell.Offset(0, 2).Value = CDate(Now)
[b]                ActiveCell.Offset(0, 6).Value = Val(ListBox2.List(i))[/b]
    If datavencimento.Value = "" Then
        MsgBox "Data de Vencimento exigida!"
        Exit Sub
    Else
        ActiveCell.Offset(0, 8).Value = CDate(datavencimento.Value)
    End If
    If dataenvio.Value = "" Then
        MsgBox "Data de Envio exigida!"
        Exit Sub
    Else
        ActiveCell.Offset(0, 13).Value = CDate(dataenvio.Value)
    End If

ActiveCell.Offset(0, 9).Value = historico.Text
ActiveCell.Offset(0, 10).Value = "ABERTA"
ActiveCell.Offset(0, 11).Value = Val(ListBox2.List(i))
                
        End If
    Next

ActiveWorkbook.Save

MsgBox "Lançamento realizado com sucesso!"

End Sub


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.


chook
Colaborador
Colaborador
Mensagens: 13
Registrado em: Qua Mar 14, 2012 9:19 am

Re: Listbox - Retorno de Valor de outra coluna

Mensagem por chook »

Resolvido com o código abaixo:

Altarada a linha para ActiveCell.Offset(0, 6).Value = CDbl(ListBox2.List(i, 2))

Código: Selecionar todos

Private Sub CommandButton3_Click()
Dim i, j, UltimaLinha As Integer
Const FOR_READING = 1
Const FOR_WRITING = 2
Const FOR_APPENDING = 8

    For i = 0 To ListBox2.ListCount - 1
        If ListBox2.List(i) = True Then
                Sheets("Contas_Pagar").Activate 'Seleciona a planilha Banco
                Range("3:3").Select 'Seleciona a Linha 2 para inserção de nova linha
                Selection.Insert Shift:=xlDown 'Insere uma linha e coloca o banco para baixo
                Range("A3").Select 'Seleciona a primeira celula da base para inserção de dados

                ActiveCell.Value = Range("A4").Value + 1
                ActiveCell.Offset(0, 1).Value = "GRAFICA E EDITORA REVENDA PRINT LTDA"
                ActiveCell.Offset(0, 2).Value = CDate(Now)
                ActiveCell.Offset(0, 6).Value = CDbl(ListBox2.List(i, 2))

    If datavencimento.Value = "" Then
        MsgBox "Data de Vencimento exigida!"
        Exit Sub
    Else
        ActiveCell.Offset(0, 8).Value = CDate(datavencimento.Value)
    End If
    If dataenvio.Value = "" Then
        MsgBox "Data de Envio exigida!"
        Exit Sub
    Else
        ActiveCell.Offset(0, 13).Value = CDate(dataenvio.Value)
    End If

ActiveCell.Offset(0, 9).Value = historico.Text
ActiveCell.Offset(0, 10).Value = "ABERTA"
ActiveCell.Offset(0, 11).Value = Val(ListBox2.List(i))
                
        End If
    Next

ActiveWorkbook.Save

MsgBox "Lançamento realizado com sucesso!"

End Sub


Responder