eddmar1993
New Member
- Joined
- May 7, 2019
- Messages
- 2
Hello! I am just new to this site and new to VBA.
I have two listboxes (Months and Product Names). I set these to 1-fmMultiSelectMulti. What I wanted is that every time I click OK button new sheets will be added with names as in the listbox(Months) and the selected items from listbox(Product Names) will be transfer to "D1" of the new sheets. I want it to offset columns.
I am fine with listbox(Months). This is my code:
My problem now is the second listbox(Product Names). I want the codes to be in the cmdOK.
Anyone can help me?
I have two listboxes (Months and Product Names). I set these to 1-fmMultiSelectMulti. What I wanted is that every time I click OK button new sheets will be added with names as in the listbox(Months) and the selected items from listbox(Product Names) will be transfer to "D1" of the new sheets. I want it to offset columns.
I am fine with listbox(Months). This is my code:
Code:
Private Sub cmdOK_Click()
Dim sName As String
Dim x As Integer
Dim ws As Worksheet
For x = 0 To lbMonths.ListCount - 1
If lbMonths.Selected(x) = True Then
sName = lbMonths.List(x)
Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
ws.Name = sName
Else: Exit Sub
End If
Next x
End Sub
My problem now is the second listbox(Product Names). I want the codes to be in the cmdOK.
Anyone can help me?