Button to change selection in ListBox

Boechat

New Member
Joined
Jul 16, 2016
Messages
44
Hey everyone, I'm facing the following problem:

I have a table where Column A gives me Names and column B gives me the status "done" or "ongoing".
I have a ListBox that populates with all names from column A.
I want to be able to select an item in the List and click a button to change the status in column B for the selected name to "DONE".

There are no userforms.

How would the code for the Button click look like?

Thanks!
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,208
Office Version
2007
Platform
Windows
If you have a listbox and a commanbutton of ActiveX controls




Use this:

Code:
Private Sub CommandButton1_Click()
    If ListBox1.ListIndex = -1 Then
        MsgBox "Select a name"
    Else
        Cells(ListBox1.ListIndex + 2, "B").Value = "done"
    End If
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,835
Office Version
365
Platform
Windows
Cross posted https://www.excelforum.com/excel-pr...click-pulling-information-from-a-listbox.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,666
Messages
5,488,182
Members
407,631
Latest member
Mehezabin

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top