Excel planilha vba combobox carrega listbox

Qua, 16 de Novembro de 2011 13:53 Expedito Marcondes
Imprimir

Escola Saberexcel VBA Estudos - o site de quem precisa aprender sobre Macros MS Excel VBA

Esses procedimentos do aplicativo Microsoft Excel VBA, carrega objetos combobox ao abrir o userform,
e ao selecionar um ítem nesta combobox , montará uma listbox com os códigos dos lotes, inserindo o valor (código)
em uma textbox editavel, podendo mudar os valores do grupo de lotes na folha de planilha.

'- - - - - - - - - - - - - - - - -
Private Sub cbCODLOTE_Change()
Dim vArea As Excel.Range
Dim vIntervalo As Excel.Range
    Dim vItem As Integer
Set vArea = Range("B2:B11")
   
    Me.lstLISTA.Clear
    For Each vIntervalo In vArea.Cells
        If vIntervalo Like Me.cbCODLOTE Then
                Me.lstLISTA.AddItem
                Me.lstLISTA.List(vItem, 0) = vIntervalo.Offset(0, -1)
                Me.lstLISTA.List(vItem, 1) = vIntervalo
                Me.lstLISTA.List(vItem, 2) = vIntervalo.Offset(0, 1)
                Me.lstLISTA.List(vItem, 3) = vIntervalo.Offset(0, 2)
                vItem = vItem + 1
        End If

    Next
Me.TextBox1 = ""
End Sub
'- - - - - - - - - - - - - - - - -

Private Sub CommandButton1_Click()
 Cells.Replace What:=cbCODLOTE.Value, Replacement:=TextBox1.Value, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
       
    [c1].Select
    Unload Me
    frmLISTADADOS.Show
End Sub
'- - - - - - - - - - - - - - - - -
Private Sub lstLISTA_Click()
Me.TextBox1 = Me.lstLISTA.List(vItem, 1)
End Sub
'- - - - - - - - - - - - - - - - -
'isso poderá travar o formulário (loop)
'Private Sub TextBox1_Change()
'Dim VL As Range
'Set VL = [B2:B100]
'For Each VL In Selection
'If VL = Me.lstLISTA.List(vItem, 1) Then
'   VL = Me.TextBox1.Value
'End If
'Next
'End Sub
'- - - - - - - - - - - - - - - - -
Private Sub UserForm_Initialize()
Me.cbCODLOTE = "SELECIONE UM CÓDIGO"
Me.TextBox1.Value = ""
SendKeys "%{down}"
End Sub
'- - - - - - - - - - - - - - - - -
Escola Saberexcel VBA Estudos Treinamentos com Macros, Fórmulas e Funções
'- - - - - - - - - - - - - - - - -



Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.



  Baixe o exemplo de planilha contendo os procedimentos acima:
Excel planilha vba pesquisa combobox e listbox (86.94 KB)

Tags:
Última atualização em Qua, 16 de Novembro de 2011 14:21