Listbox Value

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
I would like a listbox to list the following text but do not know how to do it, can someone please help.

Row 1 in the listbox would be the word - Help File
Row 2 in the listbox would be the word - Log File

I want it to have many other words but if someone gets me started I can manipulate the rest.

I want it to contain text so that when I click my activate button it will run macros based on the text that I have selected.

thanks
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,493
Office Version
2016
Platform
Windows
I would like a listbox to list the following text but do not know how to do it, can someone please help.

Row 1 in the listbox would be the word - Help File
Row 2 in the listbox would be the word - Log File

I want it to have many other words but if someone gets me started I can manipulate the rest.

I want it to contain text so that when I click my activate button it will run macros based on the text that I have selected.

thanks
Are Help File and Log File Macro names ? If so they shouldn't contain an empty space.
 

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,283
easiest way is to put all texts you need in a cell range somewhere. Then in the ListBox Properties Window put this range in the RowSource property - something like:
=Sheet1!A1:A10
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
Thanks.
The help and log files are names and you are right they would actually be set up as Help_File and Log_File, I do not want to paste the data into the sheet as it is a large sheet and I don't want to have to insert sheets and then delete them later.

Surely there must be a way you can type the names into the script yourself like a textbox or label etc...
 

Zyel

Board Regular
Joined
Jun 2, 2009
Messages
75
Thanks.
The help and log files are names and you are right they would actually be set up as Help_File and Log_File, I do not want to paste the data into the sheet as it is a large sheet and I don't want to have to insert sheets and then delete them later.

Surely there must be a way you can type the names into the script yourself like a textbox or label etc...
You can create a "Control" where it contains all sorts of control data for u

In this case, it will contain all the Items that you wan to include in the ListBox. So if in future, u dont wan certain items, just go to Control and delete the line.
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
Hi Zyel,

How do I create the control and would I be able to click on one of the names such as Help_File and have it run a macro.
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,493
Office Version
2016
Platform
Windows
Add a ListBox to Sheet1 and put the following in the Workbook module :

Workbook example.

Code:
Option Explicit
 
Private WithEvents oCmbtn As CommandButton
 
Private Sub Workbook_Open()
 
    With Sheet1.ListBox1
        .Clear
        .AddItem "Help_File"
        .AddItem "Log_File"
        Set oCmbtn = .Parent.CommandButton1
    End With
    
End Sub
 
Private Sub oCmbtn_Click()
 
    With Sheet1.ListBox1
        If .ListIndex = -1 Then
            MsgBox "Select A Macro Name first"
        Else
            Application.Run Me.CodeName & "." & .Text
        End If
    End With
    
End Sub

Private Sub Help_File()
 
    MsgBox "Macro 'Help_File' running"
 
End Sub
 
Private Sub Log_File()
 
    MsgBox "Macro 'Log_File' running"
 
End Sub
 

Forum statistics

Threads
1,082,023
Messages
5,362,725
Members
400,687
Latest member
jomelprototype

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top