Notifications
Clear all

Preencher um listbox utilizando um textbox

4 Posts
2 Usuários
0 Reactions
1,062 Visualizações
(@robertonl)
Posts: 0
New Member
Topic starter
 

Preciso preencher um listbox com 5 colunas.utilizando um textbox. Porem consegui um exemplo, porem eu não consigo que a informação seja preenchida.
Ele puxa somente uma informação e repetida em duas colunas
As informações tera que ser puxada da planilha produtofornecedor.
Se tiver uma maneira mais facil de adaptar

 
Postado : 28/06/2015 12:02 am
(@robertonl)
Posts: 0
New Member
Topic starter
 

Apos algumas alterações ele está preenchendo as cinco colunas, porém está incluindo também a linha dois
Segue a fonte com a alteração
Sub FindAllMatches()
'Find all matches on activesheet
'Called by: TextBox_Find_KeyUp event

Dim SearchRange As Range
Dim FindWhat As Variant
Dim FoundCells As Range
Dim FoundCell As Range
Dim arrResults() As Variant
Dim lFound As Long
Dim lSearchCol As Long
Dim lLastRow As Long
Dim i As Variant

If Len(RelReceb.Pesq_Prod.Value) > 1 Then 'Do search if text in find box is longer than 1 character.

Range("a3").Select

'For i = 0 To List_Corpo.ListCount - 1
'List_Corpo.ColumnCount = 5

'Next i

Set SearchRange = ActiveSheet.UsedRange.Cells

FindWhat = RelReceb.Pesq_Prod.Value
'Calls the findall function
Set FoundCells = FindAll(SearchRange:=SearchRange, _
FindWhat:=FindWhat, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
MatchCase:=False, _
BeginsWith:=vbNullString, _
EndsWith:=vbNullString, _
BeginEndCompare:=vbTextCompare)
If FoundCells Is Nothing Then
ReDim arrResults(1 To 1)
ReDim arrResults(1 To 2)
ReDim arrResults(1 To 3)
ReDim arrResults(1 To 4)
ReDim arrResults(1 To 5)
arrResults(1, 3) = "Dados não cadastrado"
Else
'Add results of FindAll to an array
ReDim arrResults(1 To FoundCells.Count, 1 To 1)
ReDim arrResults(1 To FoundCells.Count, 1 To 2)
ReDim arrResults(1 To FoundCells.Count, 1 To 3)
ReDim arrResults(1 To FoundCells.Count, 1 To 4)
ReDim arrResults(1 To FoundCells.Count, 1 To 5)
lFound = 1
For Each FoundCell In FoundCells
arrResults(lFound, 1) = FoundCell.Value
arrResults(lFound, 2) = FoundCell.Value
arrResults(lFound, 3) = FoundCell.Value
arrResults(lFound, 4) = FoundCell.Value
arrResults(lFound, 5) = FoundCell.Value
lFound = lFound + 1
Next FoundCell
End If

'Populate the list_corpo with the array
Me.List_Corpo.List = arrResults
'List_Corpo.ColumnCount = 5

Else
Me.List_Corpo.Clear
End If

End Sub

 
Postado : 28/06/2015 1:00 pm
(@joilsondo)
Posts: 47
Trusted Member
 

Boa tarde robertonl,

Eu uso o código abaixo para preencher 8 colunas do ListBox.
São 8 textboxes diferentes que preenchem 8 colunas no ListBox.

Creio que dará para você adaptar com 05 colunas.

Boa sorte!
Espero ter ajudado!

Código:

Private Sub incluir_Click()

If codinterno.Value = "" Then
MsgBox "Dados não preenchidos", vbCritical, "Erro"
nitem.SetFocus
Exit Sub
End If


'Inclui os dados para o listbox
With ListBox1
If .ListCount = 0 Then
Li = .ListCount
Else
Li = .ListCount
End If
.ColumnCount = 8
.ColumnWidths = "45;70;370;80;75;75;70;70"


.AddItem
.List(.ListCount - 1, 0) = nitem.Text
.List(.ListCount - 1, 1) = codinterno.Text
.List(.ListCount - 1, 2) = descricao.Text
.List(.ListCount - 1, 3) = qtditem.Text
.List(.ListCount - 1, 4) = unmedida.Text
.List(.ListCount - 1, 5) = valorunit.Text
.List(.ListCount - 1, 6) = referentenf.Text
.List(.ListCount - 1, 7) = emissaonf.Text


nitem.Value = ""
codinterno.Value = ""
descricao.Value = ""
qtditem.Value = ""
unmedida.Value = ""
valorunit.Value = ""
referentenf.Value = ""
emissaonf.Value = ""


'|Após incluir os dados o foco volta para o controle do nº do item

Me.nitem.SetFocus


End With




End Sub
 
Postado : 29/06/2015 12:06 pm
(@robertonl)
Posts: 0
New Member
Topic starter
 

Preciso preencher um listbox com 5 colunas.utilizando um textbox. Porem consegui um exemplo, porem eu não consigo que a informação seja preenchida.
Ele puxa somente uma informação e repetida em duas colunas
As informações tera que ser puxada da planilha produtofornecedor.
Se tiver uma maneira mais facil de adaptar

Não foi do jeito acima, mas consegui resolver.
Valeu pela atenção

 
Postado : 03/07/2015 2:04 pm