![]() |
please help
Hi,
i have a requirement. i have five buttons on a sheet, and when user clicks on a button, a form with a listbox will be displayed. the listbox will be poppulated with the data based on which button user has selected. i mean, each button click event will generate a unique array, and all the member of array will be added to the listbox in the form. i can create five different form to do that. but i want to know that, can i use the same form to perform this operation for all five buttons? Thanks, King. |
please help
Certainly you can.
create your userform, name it frmTest add to it a listbox, name is lstData create a private sub routine named, PopulateData private sub PopulateData dim iLoop as integer for iLoop = 1 to 100 'If you choose option A lstData.additem "Option " & CurrentOption & " Item " & iLoop 'If you choose option B lstData.additem "Option " & m_CurrentOption & " Item " & iLoop next iLoop end sub now then, option A add a module, name is basMain in the module create a public variable CurrentOption -- Option Explicit -- public CurrentOption as Integer Option B in the userform code module create a public routine sub, named Init and a private variable, m_CurrentOption --Public Sub Init(buttonoption as integer) -- m_CurrentOption = buttonoption --End Sub Finally on Button Click of each of your buttons OpenForm <ButtonOption private sub OpenForm(ButtonOption as integer) dim f as frmTest set f = new frmTest if option a then CurrentOption = ButtonOption if option b then f.init ButtonOption f.show vbmodal end sub "King" wrote in message oups.com... Hi, i have a requirement. i have five buttons on a sheet, and when user clicks on a button, a form with a listbox will be displayed. the listbox will be poppulated with the data based on which button user has selected. i mean, each button click event will generate a unique array, and all the member of array will be added to the listbox in the form. i can create five different form to do that. but i want to know that, can i use the same form to perform this operation for all five buttons? Thanks, King. |
All times are GMT +1. The time now is 03:56 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com