VBA Listbox

ryancgarrett

Board Regular
Joined
Jun 18, 2011
Messages
122
I have a form in VBA and it has some option buttons that populate a listbox when they are selected. Based on the selection in the listbox I need to copy a sheet template and rename it to the selection, as well as put the name of the selection in cell B2 of the sheet. This is my code that doesn't work... any suggestions?

Sub AddAccount()

Sheets("Account Template").Copy after:=Sheets("Trial Balance")
Sheets(2).Name = frmAddAccount.lbxAccountName.Selected
Sheets(2).Cells(2, 2).Value = frmAddAccount.lbxAccountName.Selected
Sheets("Trial Balance").Range ("B" & BlankRow("Trial Balance", 4, 2))

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Instead of frmAddAccount.lbxAccountName.Selected, you should use the .Value property of the listbox, frmAddAccount.lbxAccountName.Value.


(The .Selected property of a list box is a boolean array of whether an item is selected or not. It is useful for multi-select list boxes, but not in your application.)
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,875
Members
452,949
Latest member
Dupuhini

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