Show some columns in Listbox

Asked

Viewed 18 times

0

I am building a system for my company, where when I click on a button it is bringing me all the columns of the table, but I would like to specify which columns I want to display. Since these columns are not on each other’s side.

txtResult1.RowSource = Range("A1").CurrentRegion.Address

1 answer

0


Assuming you are using Listbox, it will not be possible to directly add multiple ranges in the Rowsource property.

You need to set your range before and scroll through it by adding the items inside your Listbox.

Take an example:

Aqui temos meu intervalo em diferentes colunas

Now look at my code:

Dim intervalo       As Range 'crio uma variável do tipo Range
Set intervalo = Sheets("NomeDaSuaAba").Range("F3:F6,J3:J7") ' Aqui informo quais são meus intervalos que eu quero adicionar ao meu range

For Each cell In intervalo ' percorro meu intervalo
    ListBox1.AddItem cell.Value 'adiciono o valor da celula dentro do meu listbox
Next

My final result:

Imagem final

This is only one way to do it, but there are several ways, each with its advantages and disadvantages.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.