VBA- Listbox - ColumnCount>1 - adjust Column width

Rasm

Well-known Member
Joined
Feb 9, 2011
Messages
505
I am using a Listbox with a ColumnCount of 5 - I have two questions

1) How to adjust column width using the graphical GUI - similar to what you do when you adjust a column width in Excel itself using the mouse and click and drag.

2) How can I sort the entries in the listbox - is there a property similar to ExploreBar - in other words I would like to click in the header and then it sorts ascending - if you click again it sorts decenting.
 
To sort ascending/descending:
Code:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
   With ListView1
      If .SortKey = ColumnHeader.Index - 1 Then
         If .SortOrder = lvwAscending Then
            .SortOrder = lvwDescending
         Else
            .SortOrder = lvwAscending
         End If
      Else
         .SortKey = ColumnHeader.Index - 1
      End If
       .Sorted = True
  End With
End Sub

for example.
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
As long as the Common Controls are available, it should be fine - unless you are running 64bit Office!
 
Upvote 0
Guys - I luve it - The Listview is giving me no headaches - it is sweet to work with - I use the .View = 3 Now it looks and feels like a Listbox on steroids - I also used Andy Popes Resizer for the userforms - I added frames on my userform - that way I can resize my objects on the userform as well with less code.

I will check the sort function tom - Thanks
 
Upvote 0
All the help you guys gave me - inspired me to prepare an upload on how to use Listview - I am going to going to post it on Excelfox.com - new forum - check it out.

I did encounter a problem with the MScomctl.OCX - somehow the .ColumnHeader in the ColumnClick got broke - but just had to re-reg the OCX.

Thanks again :biggrin: - all this Excel stuff is hurting my poker game time - lol - guess thats good for my vallet.:eeek:
 
Upvote 0

Forum statistics

Threads
1,224,540
Messages
6,179,417
Members
452,912
Latest member
alicemil

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