Listbox multiple column advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
I have the code in use below but im only getting the first column values.
Do you see an issue with the 2nd & 3rd

Thanks

Rich (BB code):
Private Sub UserForm_Initialize()
    Dim rng As Range, cel As Range
For Each cel In Range("F6", Range("F" & Rows.Count).End(xlUp))
    If IsEmpty(cel) Then
        With Me.ListBox1
            .ColumnCount = 3
            .ColumnWidths = "100;150;90"
            .AddItem
            .List(.ListCount - 1, 0) = cel.Offset(, -5).Value
            .List(.ListCount - 1, 2) = cel.Offset(, -8).Value
            .List(.ListCount - 1, 3) = cel.Offset(, -11).Value
        End With
    End If
Next cel

    '-------------------------------
    Me.StartUpPosition = 0
    Me.Top = Application.Top + 50  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 440 ' LEFT / RIGHT OF SCREEN
   
    '-------------------------------

End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I don't have enough time, but You're wrong , how you have columns -8,-11 when move to left before column F?!
the column maximum you have -5 is column(A). if you want showing A,B,C columns then will be -5,-4,-3
 
Upvote 0
That is why i dont understand the correct format to get it working.
I know im wrong so looking for help
 
Upvote 0
just read well my comment will you solve your problem as I think.
 
Upvote 0
With the code below i now get 3 columns with values BUT all values are from column A on worksheet
Ive altered the numbers but either then fails or i see no values.

Which do i edit to see correct values in listbox columns


Rich (BB code):
Private Sub UserForm_Initialize()
    Dim rng As Range, cel As Range
For Each cel In Range("F6", Range("F" & Rows.Count).End(xlUp))
    If IsEmpty(cel) Then
        With Me.ListBox1
            .ColumnCount = 3
            .ColumnWidths = "100;100;100"
            .AddItem
            .List(.ListCount - 1, 0) = cel.Offset(, -15).Value
            .List(.ListCount - 1, 2) = cel.Offset(, -15).Value
            .List(.ListCount - 1, 1) = cel.Offset(, -15).Value
        End With
    End If
Next cel

    '-------------------------------
    Me.StartUpPosition = 0
    Me.Top = Application.Top + 50  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 440 ' LEFT / RIGHT OF SCREEN
   
    '-------------------------------

End Sub
 
Upvote 0
change this
VBA Code:
.List(.ListCount - 1, 2) = cel.Offset(, -8).Value
            .List(.ListCount - 1, 3) = cel.Offset(, -11).Value

to this (as bold numbers)
Rich (BB code):
.List(.ListCount - 1, 2) = cel.Offset(, -4).Value
            .List(.ListCount - 1, 3) = cel.Offset(, -3).Value
this is my guessing.
now I should leave.;)
 
Upvote 0
Didnt make a difference & this is the code in use so will advise how i need it to work but dont understand the meaning of the digits used.
Please use this code only now & not the above.

The code looks for a cell in column F that has no value "SO BELOW ITS -5 VALUE"
The code then takes the value from column A & populates listbox "SO COLUMN A IS 0"

So i now need same to happen for column B "SO USING VALUE 1" & also column C "SO VALUE 2"

Listbox should show,
Worksheet column A to listbox 1st column
Worksheet column B to listbox 2nd column
Worksheet column C to listbox 3rd column

Thats my limited understanding but when i alter the values belwo the following happens,
Listbox values are all the same.
Only partial columns in Listbox get populated.
Code doesnt run & i see a error Could not set the list property

YOU WOULD OF THOOUGHT BY CHANGING THE VALUE AT LEAST SOMETHING IN LISTBOX WOULD BE CORRECT BUT NOT SO
Please see screenshot.

So i await the anser to my issue.
Thanks


Rich (BB code):
Private Sub UserForm_Initialize()
    Dim rng As Range, cel As Range
For Each cel In Range("F6", Range("F" & Rows.Count).End(xlUp))
    If IsEmpty(cel) Then
        With Me.ListBox1
            .ColumnCount = 3
            .ColumnWidths = "100;100;100"
            .AddItem
            .List(.ListCount - 1, 0) = cel.Offset(, -5).Value
            .List(.ListCount - 1, 1) = cel.Offset(, -5).Value
            .List(.ListCount - 1, 2) = cel.Offset(, -5).Value
        End With
    End If
Next cel

    '-------------------------------
    Me.StartUpPosition = 0
    Me.Top = Application.Top + 50  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 440 ' LEFT / RIGHT OF SCREEN
   
    '-------------------------------

End Sub
 

Attachments

  • EaseUS_2024_02_ 4_11_40_56.jpg
    EaseUS_2024_02_ 4_11_40_56.jpg
    87.4 KB · Views: 6
Upvote 0
VBA Code:
Private Sub UserForm_Initialize()
    Dim lr As Long
    Dim rng As Range, cel As Range

lr = Range("A" & Rows.Count).End(xlUp).Row
For Each cel In Range("F6:F" & lr)
    If IsEmpty(cel) Then
        With Me.ListBox1
            .ColumnCount = 3
            .ColumnWidths = "100;100;100"
            .AddItem
            .List(.ListCount - 1, 0) = cel.Offset(, -5).Value 'value in column A which is 5 cells to the left of cel
            .List(.ListCount - 1, 1) = cel.Offset(, -4).Value 'value in column B which is 4 cells to the left of cel
            .List(.ListCount - 1, 2) = cel.Offset(, -3).Value 'value in column C which is 3 cells to the left of cel
        End With
    End If
Next cel

    '-------------------------------
    Me.StartUpPosition = 0
    Me.Top = Application.Top + 50  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 440 ' LEFT / RIGHT OF SCREEN
   
    '-------------------------------

End Sub
 
Upvote 0
@ipbr21054
I don't understanding in your last posts repeat the same column for each column in listbox
Ive altered the numbers but either then fails
you don't do that . just concentrate .
I hope you've found where is your bad . just read comments in NoSparks' code.;)
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,097
Members
449,096
Latest member
provoking

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