473,670 Members | 2,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel VBA Listbox

risk32
98 New Member
Hello.
I am having a problem with Excel VB. I'm trying to use the value of items in a listbox to manipulate a caption to a label. Any suggestions? I haven't tried to use index, and frankly I don't know how.

Here's what' I've started with:
With lbDay1
.AddItem "01"
.AddItem "02"
.AddItem "03"
.AddItem "04"
.AddItem "05"
.AddItem "06"
.AddItem "07"
.AddItem "08"
.AddItem "09"
.AddItem "10"
.AddItem "11"
.AddItem "12"
.AddItem "13"
.AddItem "14"
.AddItem "15"
End With
........
Private Sub lbDay1_Click()
lbDay1.Value = lblLink2.Captio n
End Sub
Aug 21 '08 #1
2 3092
MikeTheBike
639 Recognized Expert Contributor
Hello.
I am having a problem with Excel VB. I'm trying to use the value of items in a listbox to manipulate a caption to a label. Any suggestions? I haven't tried to use index, and frankly I don't know how.

Here's what' I've started with:
With lbDay1
.AddItem "01"
.AddItem "02"
.AddItem "03"
.AddItem "04"
.AddItem "05"
.AddItem "06"
.AddItem "07"
.AddItem "08"
.AddItem "09"
.AddItem "10"
.AddItem "11"
.AddItem "12"
.AddItem "13"
.AddItem "14"
.AddItem "15"
End With
........
Private Sub lbDay1_Click()
lbDay1.Value = lblLink2.Captio n
End Sub
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub UserForm_Initialize()
  4.     With lbDay1
  5.         .AddItem "01"
  6.         .AddItem "02"
  7.         .AddItem "03"
  8.         .AddItem "04"
  9.         .AddItem "05"
  10.         .AddItem "06"
  11.         .AddItem "07"
  12.         .AddItem "08"
  13.         .AddItem "09"
  14.         .AddItem "10"
  15.         .AddItem "11"
  16.         .AddItem "12"
  17.         .AddItem "13"
  18.         .AddItem "14"
  19.         .AddItem "15"
  20. End With
  21.  
  22. End Sub
  23.  
  24. Private Sub lbDay1_Click()
  25.     lblLink2.Caption = lbDay1
  26. End Sub
  27.  
??

MTB
Aug 21 '08 #2
risk32
98 New Member
More coding might be of some help... Do you know how to add pictures to this?

Private Sub cmdBack_Click()
MultiPage1.Valu e = 0
End Sub

Private Sub cmdNext_Click()
MultiPage1.Valu e = 1
End Sub

Private Sub cmdGenerate_Cli ck()
MultiPage1.Valu e = 2
lblLink = "\\yofs13\374OG \36AS\Asgard_da ta\data\Duty Desk\Electronic Boards Info\Schedule Slides\2008\"
End Sub

Private Sub Form_Load()
lblAirfield.Set Focus
End Sub

Private Sub txtYear_click()
txtYear.MaxLeng th = 2
If txtYear = "" Then
MsgBox "Please enter a year"
txtYear.SetFocu s
End Sub

Private Sub cmdGo_Click()
Shell ("C:\Program Files\Microsoft Office\OFFICE12 \POWERPNT.EXE " & Chr(34) & lblLink.Caption & Chr(34))
End Sub

Private Sub lbDay1_Click()
lbDay1.Value = lblLink2.Captio n
End Sub

Private Sub optAirfield_Cli ck()
If optAirfield.Val ue = True Then
MultiPage1.Valu e = 2
End If
lblLink = "\\yofs13\374OG \36AS\Asgard_da ta\data\Duty Desk\Electronic Boards Info\Schedule Slides\2008\INF O & STATUS\Info And Status.ppt"
lblLink = lblLink.Caption
End Sub

Private Sub optSched_Click( )
If optSched.Value = True Then
MultiPage1.Valu e = 1
With lbDay1
.AddItem "01"
.AddItem "02"
.AddItem "03"
.AddItem "04"
.AddItem "05"
.AddItem "06"
.AddItem "07"
.AddItem "08"
.AddItem "09"
.AddItem "10"
.AddItem "11"
.AddItem "12"
.AddItem "13"
.AddItem "14"
.AddItem "15"
End With
With lbDay2
.AddItem "16"
.AddItem "17"
.AddItem "18"
.AddItem "19"
.AddItem "20"
.AddItem "21"
.AddItem "22"
.AddItem "23"
.AddItem "24"
.AddItem "25"
.AddItem "26"
.AddItem "27"
.AddItem "28"
.AddItem "29"
.AddItem "30"
.AddItem "31"
End With
With lbMonth
.AddItem "January"
.AddItem "February"
.AddItem "March"
.AddItem "April"
.AddItem "May"
.AddItem "June"
.AddItem "July"
.AddItem "August"
.AddItem "September"
.AddItem "October"
.AddItem "November"
.AddItem "December"
End With
End If

End Sub
Aug 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
8500
by: Jean | last post by:
Hello, I have a form that performs a search, according to criteria that a user enters into the text boxes. When the user clicks on „Search", a SQL string (say strSQL) is built up with the criteria. Then a list box RowSource property is set to this strSQL, to display the results of the search. StrSQL is a global variable within this Form's code module, i.e. in the class module.
3
8920
by: Conrad F | last post by:
Hello All, I know how to import a specific named excel sheet into a datagrid using ADO.NET by setting up a JET connection and then SELECTing data from the sheet. However, for a real world application, I would typically not know what the names of the sheets are going to be before I open the Excel file. I am wondering if there is a SELECT statement that would get me the list of sheet names so that I can place them in a combobox and
3
8892
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C Me.ListBoxPerson.Items.AddRange(ary)
0
1106
by: Piotr Kosinski | last post by:
Hi, I noticed strange behaviour in Excel. I wrote small shared add in for Excel. This util create button in standard bar. Button click provides to open a form which has to import data from sql server and present on listbox, double click date should be paste into activecell in excel. Because shared add in is loaded with excel i use: myexcel = getobject(, "excel.application")
18
8279
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a given cell. region.Value2="qwe"; //bumm! A exception will be trown. On all PCs with excel. HRESULT 0x800A03EC
1
5731
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access database - containing a list of addresses. Sequence of events is = (1) Excel template opens in its default XXX.xls filename. (2) Code runs to save the spreadsheet as XXX.xls. (3) User clicks a button to open an Access database containing an
1
2790
by: bbasberg | last post by:
Hello, I am wondering how to "carry over" a value from a listbox on one worksheet in the workbook to a cell in another worksheet in the same workbook. For example, to just copy over a value from a textbox (as opposed to a listbox), this code in the destination cell does the trick: ='Source Worksheet Name'!E21 where E21 is the cell in the source (origin) worksheet that has the data. With a listbox in the source worksheet, I see the...
2
1791
by: dan NY | last post by:
I'm a struggling new VB Applications user that has what may be a simple question, but I've been struggling with it. I'm using a response to a message box YesNo question to cause one of two previously created listboxes to populate. These listboxes are each linked to ranges of cells that appear or are blanked out by IF statements in excel formulas =IF(a1=1,"company name","") - the contents of cell A1 becomes 1 based on an affirmative response...
18
4598
by: Zytan | last post by:
I want the same function to be run whether you press Enter or double click the listbox. It seems really verbose to write both handlers to both events everytime, even if they both call the same function, or one calls the other. Isn't there an event for 'ListBox selection selected' that is automatically called by ALL the standard GUI ways of doing it? C'mon, this is C#, we aren't supposed to be programming the GUI. There has to be such...
5
6376
by: GeorgeBro | last post by:
I am having a problem trying to select items from a listbox that is drawn on my worksheet. I have no problem adding items, or removing items.... only when I try to identify the items that are selected. There is no ".Selected" in the intellisense for either the object directly, or the object.ControlFormat. When I execute this code, Excel fails with the error message: "Runtime Error 438. Object doesn't support this property or method." ...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7415
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2799
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.