Listbox with certain columns+last row

vinidis

New Member
Joined
Aug 11, 2017
Messages
8
Hi all!

I have a multi issue here with a listbox.
I'd like to make a listbox that shows only the selected columns with filtered data of my Database sheet. That page has 13 columns ("A:M") with data but I need only the A, C, D, and K columns to be visible. The last row needs to be dynamic and the filter is the all-time month. The 9th column ("I") has dates that needs to be filtered.
I have a code from my other listbox that is a simple one with a dynamic last row and headers.

VBA Code:
Private Sub ListBox1()

    Dim sh As Worksheet
    Dim last_Row As Long
   
        Set sh = ThisWorkbook.Sheets("Database")
        last_Row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
           
            With Me.ListBox1
                        .ColumnHeads = True
                        .ColumnCount = 13
                        .ColumnWidths = "30,60,50,60,70,60,45,85,60,55,60,150,70"
                   
                            If last_Row = 1 Then
                                .RowSource = "Database!A2:M2"
                            Else
                                .RowSource = "Database!A2:M" & last_Row
                            End If
            End With

End Sub

Can I add a selected column list to this somehow or it is better to write a new one? I've tried this code with array but didn't work.
Thanks for the help.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Olá a todos!

Eu tenho um problema multi aqui com uma caixa de listagem.
Eu gostaria de fazer uma caixa de listagem que mostrasse apenas as colunas selecionadas com dados filtrados da minha planilha de banco de dados. Essa página tem 13 colunas ("A:M") com dados, mas preciso que apenas as colunas A, C, D e K estejam visíveis. A última linha precisa ser dinâmica e o filtro é o mês de todos os tempos. A 9ª coluna ("I") possui datas que precisam ser filtradas.
Eu tenho um código da minha outra caixa de listagem que é simples com uma última linha e cabeçalhos dinâmicos.

[CÓDIGO=vba]
Sublista privada privada1()

Dim sh como planilha
Dim last_Row As Long

Set sh = ThisWorkbook.Sheets("Database")
last_Row = Application.WorksheetFunction.CountA(sh.Range("A:A"))

Comigo.ListBox1
.ColumnHeads = Verdadeiro
.ColumnCount = 13
.ColumnWidths = "30,60,50,60,70,60,45,85,60,55,60,150,70"

Se last_Row = 1 Então
.RowSource = "Banco de dados!A2:M2"
Outro
.RowSource = "Banco de dados!A2:M" & last_Row
Fim se
Terminar com

Finalizar Sub
[/CÓDIGO]

Posso adicionar uma lista de colunas selecionadas a isso de alguma forma ou é melhor escrever uma nova? Eu tentei este código com array, mas não funcionou.
Obrigado pela ajuda.
Você deseja que apenas colunas selecionadas com dados filtrados apareçam no ListBox? Se sim, basta colocar "Zero" na coluna que você não quer que apareça. .ColumnWidths = "30,0,0,60,70,60,45,85,60,0,0,150,0"
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top