Excel VBA Populate Selected Items from Listbox 2 to a Range

sashimee

New Member
Joined
Aug 31, 2022
Messages
4
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. Windows
Hi All,

I am having a hard time to move or remove the items from List box 1 after selecting the button for move to List box 2. Initially, this is what I want to do:

1. Select the range of dates from Listbox 1 from a dynamic range
2. Click the >> button to move/remove dates from the Listbox 1
3. Dates from Listbox 2 must be populated on the "C" Column
4. Append after repeating the steps above (no overwriting)

VBA Code:
'working
'get items from listbox 1 to listbox 2
     'Variable declaration
    Dim iCnt As Integer
    
    'Get Selcted Items from ListBox1 to ListBox2
    For iCnt = 0 To lb1.ListCount - 1
        'Check ListBox Item has selcted or not
        If lb1.Selected(iCnt) = True Then
           lb2.AddItem lb1.List(iCnt)
       End If
    Next
    
    '=======================
        
    With Sheets("Test").lb2
    For i = 2 To int_list_end
        .AddItem .Range("C" & i).Value
    Next i
End With


Thank you for your help
 

Attachments

  • 2022-09-02 03_28_45.png
    2022-09-02 03_28_45.png
    21.5 KB · Views: 11

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi All,

I am having a hard time to move or remove the items from List box 1 after selecting the button for move to List box 2. Initially, this is what I want to do:

1. Select the range of dates from Listbox 1 from a dynamic range
2. Click the >> button to move/remove dates from the Listbox 1
3. Dates from Listbox 2 must be populated on the "C" Column
4. Append after repeating the steps above (no overwriting)

VBA Code:
'working
'get items from listbox 1 to listbox 2
     'Variable declaration
    Dim iCnt As Integer
   
    'Get Selcted Items from ListBox1 to ListBox2
    For iCnt = 0 To lb1.ListCount - 1
        'Check ListBox Item has selcted or not
        If lb1.Selected(iCnt) = True Then
           lb2.AddItem lb1.List(iCnt)
       End If
    Next
  
Thank you for your help
[/QUOTE]
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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