Notifications
Clear all

Preenchendo combobox com cabeçalho de colunas

3 Posts
2 Usuários
0 Reactions
1,241 Visualizações
(@betorubini)
Posts: 57
Trusted Member
Topic starter
 

Olá Fiz um combobox que é preenchido com o cabeçalho (primeira linha) das colunas da planilha
segue o código

Private Const NomePlanilha As String = "Agenda"
Private Const LinhaCabecalho As Integer = 1

Private Sub PreencheCampos()
    Dim ws As Worksheet
    Dim coluna As Integer
    Dim linha As Integer
    Set ws = ThisWorkbook.Worksheets(NomePlanilha)
    coluna = 1
    linha = LinhaCabecalho
    
    With ws
        While .Cells(linha, coluna).Value <> Empty
            Me.ComboBoxCampos.AddItem .Cells(linha, coluna)
            coluna = coluna + 1
            If coluna = 6 Then Exit Sub
    Wend
    End With
End Sub

mas gostaria que a coluna "2" nao fosse listada, ou seja o combobox pegaria apenas as colunas 1,3,4,5,6
Alguem tem alguma idéia
Obrigado!

 
Postado : 14/06/2013 5:19 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Se entendi corretamente, você pode utilizar uma das duas rotinas abaixo :

Private Sub PreencheCampos()
    Dim ws As Worksheet
    Dim coluna As Integer
    Dim linha As Integer
    Set ws = ThisWorkbook.Worksheets(NomePlanilha)
    coluna = 1
    linha = LinhaCabecalho
    
    With ws
        While .Cells(linha, coluna).Value <> Empty
            If coluna = 2 Then
                'Se Coluna = a 2 pula
            Else
                Me.ComboBoxCampos.AddItem .Cells(linha, coluna)

                If coluna = 6 Then Exit Sub
                
            End If
            
            coluna = coluna + 1
    
        Wend
        
    End With

End Sub
Private Sub PreencheCampos2()
    Dim ws As Worksheet
    Dim coluna As Integer
    Dim linha As Integer
    Set ws = ThisWorkbook.Worksheets(NomePlanilha)
    coluna = 1
    linha = LinhaCabecalho
    
    With ws
    
        While .Cells(linha, coluna).Value <> Empty
            If coluna <> 2 Then
                'Se Coluna Diferente de 2 preenche
                Me.ComboBoxCampos.AddItem .Cells(linha, coluna)
            Else
                'Se não Coluna = 2  pula
                 
            End If
            
            If coluna = 6 Then Exit Sub
            
            coluna = coluna + 1
    
        Wend
    End With

End Sub

[]s

 
Postado : 14/06/2013 5:55 pm
(@betorubini)
Posts: 57
Trusted Member
Topic starter
 

Opá exatamente isso!
Muito Obrigado

 
Postado : 14/06/2013 6:15 pm