VBA Listbox question

Birger021

New Member
Joined
May 9, 2019
Messages
1
Hi!

New to this forum and to VBA so I'm really hoping we have some experts present :)

Let's say I have a list of users and each user has a value for mon-fri.
IdRTRef.png

IdRTRef.png
22a6eb487e7dc8d6e259b203fc4b2ac1-full.png


What I want is a listbox with multiselect so I can select multiple users and then the userform should export those usernames J3 and the total values of those users for mon-fri in K3.


Regards
Birger
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Based on your data being in sheet1, Names in Column "A" days of week value in columns "B :F"
Headers in row 1
Userform contains Listbox1 and CommandButton1.

Then try this in you userform for selected results start in "J3/K3".
Code:
[COLOR="Navy"]Sub[/COLOR] MG09May14
Private [COLOR="Navy"]Sub[/COLOR] UserForm_Initialize()
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant
 Ray = Sheets("Sheet1").Range("A1").CurrentRegion
[COLOR="Navy"]With[/COLOR] Me.ListBox1
    .ColumnCount = 6
    .ColumnWidths = "30,30,30,30,30,30"
    .MultiSelect = fmMultiSelectMulti
    .List = Ray
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]

Private [COLOR="Navy"]Sub[/COLOR] CommandButton1_Click()
[COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] oSum [COLOR="Navy"]As[/COLOR] Double, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] R [COLOR="Navy"]As[/COLOR] Variant
c = 3
[COLOR="Navy"]With[/COLOR] Me.ListBox1
[COLOR="Navy"]For[/COLOR] n = 1 To .ListCount - 1
    [COLOR="Navy"]If[/COLOR] .Selected(n) [COLOR="Navy"]Then[/COLOR]
        c = c + 1
        Cells(c, "J") = .List(n)
        [COLOR="Navy"]With[/COLOR] Application
            Cells(c, "K") = .Sum(.Index(.Columns, n + 1, Array(2, 3, 4, 5, 6)))
        [COLOR="Navy"]End[/COLOR] With
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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