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: 10

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,215,182
Messages
6,123,517
Members
449,102
Latest member
admvlad

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