ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User to choose an item from a list (https://www.excelbanter.com/excel-programming/361977-user-choose-item-list.html)

Hari

User to choose an item from a list
 
Hi,

I want to offer user with a window containing names of the months in a
year seperately on each line.

The user would choose one of the 12 and press something like ok and I
want the month chosen by the user to be stored in a variable in my
code.

If I can get some skeleton code for similar situation I can try to
customise this for my requirements.

Please guide me as to how I may achieve the same.

Regards,
HP
India


Bob Phillips[_14_]

User to choose an item from a list
 
Create a list of month names somewhere in your workbook, and name it
(InsertNameDefine...) say Months.

Then use Data Validation (DataValidation) with a type of list and a value
of =Months.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Hari" wrote in message
oups.com...
Hi,

I want to offer user with a window containing names of the months in a
year seperately on each line.

The user would choose one of the 12 and press something like ok and I
want the month chosen by the user to be stored in a variable in my
code.

If I can get some skeleton code for similar situation I can try to
customise this for my requirements.

Please guide me as to how I may achieve the same.

Regards,
HP
India




Hari

User to choose an item from a list
 
Bob,

Thanks for the response. Iam aware of this feature of Data validation
using Named ranges.

Actually am writing some code to produce some reports and in the midst
of it I need to prompt the user about the month for which the report
needs to be generated. I want to avoid user entering his options in the
workbook itself. Rather I want this to be done at run-time of the code.
Hence, my request to offer user a window and once chosen, store user's
response in a variable.

Please guide me for the same.

regards,
HP
India

Bob Phillips wrote:
Create a list of month names somewhere in your workbook, and name it
(InsertNameDefine...) say Months.

Then use Data Validation (DataValidation) with a type of list and a value
of =Months.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Hari" wrote in message
oups.com...
Hi,

I want to offer user with a window containing names of the months in a
year seperately on each line.

The user would choose one of the 12 and press something like ok and I
want the month chosen by the user to be stored in a variable in my
code.

If I can get some skeleton code for similar situation I can try to
customise this for my requirements.

Please guide me as to how I may achieve the same.

Regards,
HP
India



Ardus Petus

User to choose an item from a list
 
You will need to define an userform.

Here is an example: http://cjoint.com/?futKV4V1wA
NB: you must double-click a month to select it

Userform code is:

'-------------
Option Explicit

Private Sub lbMonth_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.Hide
End Sub

Private Sub UserForm_Initialize()
Dim iMonth As Byte
Dim aMonthArray(12, 2) As Variant
For iMonth = 1 To 12
aMonthArray(iMonth - 1, 0) = iMonth
aMonthArray(iMonth - 1, 1) = _
Format(DateSerial(0, iMonth, 1), "mmmm")
Next iMonth
lbMonth.List = aMonthArray
End Sub
'--------------

test code (your macro) is:

'-------------
Sub test()
Dim iMonth As Integer
ufSelectMonth.Show
iMonth = ufSelectMonth.lbMonth.Value
MsgBox iMonth
End Sub
'--------------
"Hari" a écrit dans le message de news:
...
Bob,

Thanks for the response. Iam aware of this feature of Data validation
using Named ranges.

Actually am writing some code to produce some reports and in the midst
of it I need to prompt the user about the month for which the report
needs to be generated. I want to avoid user entering his options in the
workbook itself. Rather I want this to be done at run-time of the code.
Hence, my request to offer user a window and once chosen, store user's
response in a variable.

Please guide me for the same.

regards,
HP
India

Bob Phillips wrote:
Create a list of month names somewhere in your workbook, and name it
(InsertNameDefine...) say Months.

Then use Data Validation (DataValidation) with a type of list and a
value
of =Months.

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"Hari" wrote in message
oups.com...
Hi,

I want to offer user with a window containing names of the months in a
year seperately on each line.

The user would choose one of the 12 and press something like ok and I
want the month chosen by the user to be stored in a variable in my
code.

If I can get some skeleton code for similar situation I can try to
customise this for my requirements.

Please guide me as to how I may achieve the same.

Regards,
HP
India





Hari

User to choose an item from a list
 
Ardus,

Thanks for your code. It works really great.

I hope to use this technique for my other requirements as well.

Regards,
HP
India



All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com