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

Selecionados do ListBox p/ planilha

Dúvidas gerais sobre Excel
betoacunha
Colaborador
Colaborador
Mensagens: 27
Registrado em: Qua Jul 07, 2010 1:38 pm

Selecionados do ListBox p/ planilha

Mensagem por betoacunha »

Olá pessoal...

Uso o código abaixo para enviar os dados para a planilha. Na propriedade do listbox optei pela multiseleção. Não tô conseguindo adaptar este código para enviar somente os ítens que selecionei para esta planilha.

Private Sub cmdEnviar_Click()

Dim Lin As Integer

Dim Cont As Integer

Sheets("Horario").Range("A2:C1000").ClearContents

Lin = 2

For Cont = 1 To Me.lbxTurmas.ListCount - 1

Worksheets("Horario").Range("A" & Lin) = Me.lbxTurmas.List(Cont, 1)
Worksheets("Horario").Range("B" & Lin) = Me.lbxTurmas.List(Cont, 2)
Worksheets("Horario").Range("C" & Lin) = Me.lbxTurmas.List(Cont, 3)

Lin = Lin + 1
Next
End Sub

Abs e Ajuda!!!

Beto


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
Mauro Coutinho
Jedi
Jedi
Mensagens: 1561
Registrado em: Sáb Mar 13, 2010 8:10 pm
Localização: São José dos Pinhais - Pr

Re: Selecionados do ListBox p/ planilha

Mensagem por Mauro Coutinho »

Troque sua rotina pela a abixo e veja se é sito :

Código: Selecionar todos

Private Sub cmdEnviar_Click()
    Dim rStartCell As Range
    Dim iListCount As Integer, iColCount As Integer
    
    Sheets("Horario").Range("A2:C1000").ClearContents
    
    Set rStartCell = Sheets("Horario").Range("A65536").End(xlUp).Offset(1, 0)
    
        For iListCount = 0 To lbxTurmas.ListCount - 1
            If lbxTurmas.Selected(iListCount) = True Then  'User has selected
                lbxTurmas.Selected(iListCount) = False
                iRow = iRow + 1
                
                For iColCount = 0 To Range("MyRange").Columns.Count - 1
                    rStartCell.Cells(iRow, iColCount + 1).Value = _
                    lbxTurmas.List(iListCount, iColCount)
                Next iColCount
            End If
        Next iListCount
    
    Set rStartCell = Nothing

End Sub


betoacunha
Colaborador
Colaborador
Mensagens: 27
Registrado em: Qua Jul 07, 2010 1:38 pm

Re: Selecionados do ListBox p/ planilha

Mensagem por betoacunha »

È isto aí ...

Ficou perfeito, só troquei o segundo For por:

For iColCount = 1 To Me.lbxTurmas.ListCount - 1

Brigadão Mauro

Beto Cunha


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