+ Reply to Thread
Results 1 to 2 of 2

Update (strikethrough) Listbox item selected within sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    12-09-2013
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Update (strikethrough) Listbox item selected within sheet

    Hi guys

    This site has helped me a lot with my VBA but I battle to find a proper solution to my issue:

    I have a userform that search for a value in column A, it displays the results in the listbox. Example: Search for value "111" and it brings me back the following results back in the listbox "111 David 35". So this means 3 columns matching data is returned.

    I want the following to happen if I double click on the item in the listbox it needs to update the value selected in the worksheet eg. strikethrough the row on the sheet to show item has been seleced/done.

    Code for my listbox populate:

    Formula: copy to clipboard
    Dim wks As Worksheet
    Dim rg As Range
    Dim Rng As Range
    Dim first_row As Long 'use this to see if the find is looping again
    Dim ctr As Integer 'use this to show count of matching records
    Dim My_Col As String 'this is used to search part no or item description based on user input
    Set wks = Sheets("TeamList")

    ListBox1.Clear
    My_Col = "A"

    'search in the columns based on user input
    Set Rng = wks.Columns(My_Col & ":" & My_Col).Find(What:=Me.TextBox1.Value, After:=wks.Range(My_Col & wks.Rows.Count).End(xlUp))

    If Not Rng Is Nothing Then

    vl = wks.Range(Rng.Address).Value

    ctr = 0
    ListBox1.Clear
    'add the listbox column headers
    Me.ListBox1.ColumnCount = 4

    Me.ListBox1.AddItem
    Me.ListBox1.List(0, 0) = "Team Nr."
    Me.ListBox1.List(0, 1) = "Name and Surname"
    Me.ListBox1.List(0, 2) = "Meal"
    Me.ListBox1.List(0, 3) = "Drink"
    first_row = Rng.Row 'row no of the first found

    Do Until Rng Is Nothing 'loop through the range

    For Each rg In Rng.Rows
    If rg.Row > 1 Then
    ListBox1.AddItem 'add items to listbox
    ListBox1.List(ListBox1.ListCount - 1, 0) = wks.Range("A" & rg.Row).Text
    ListBox1.List(ListBox1.ListCount - 1, 1) = wks.Range("B" & rg.Row).Text
    ListBox1.List(ListBox1.ListCount - 1, 2) = wks.Range("C" & rg.Row).Text
    ListBox1.List(ListBox1.ListCount - 1, 3) = wks.Range("D" & rg.Row).Text
    ctr = ctr + 1
    End If
    Next
    Set Rng = wks.Columns(My_Col & ":" & My_Col).FindNext(After:=Rng)
    If Rng.Row = first_row Then 'check if find is looping again from the beginning ,if yes then exit do
    Exit Do
    End If
    Loop
    End If


    Appreciate your help!

  2. #2
    Registered User
    Join Date
    12-09-2013
    Location
    SA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Update (strikethrough) Listbox item selected within sheet

    I have done this dbl click so far BUT it goes to the top and not the item selected...I know it is something STUPID!!

    Formula: copy to clipboard
    Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

    Dim lngItem As Long
    Dim I As Long
    Dim msg As String

    If ListBox1.ListIndex <> -1 Then
    For I = 0 To ListBox1.ColumnCount - 1
    msg = msg & ListBox1.Column(I) & vbCrLf
    Next I
    End If

    MsgBox msg

    For lngItem = 0 To ListBox1.ListCount + I
    If ListBox1.Selected(lngItem) Then
    With Sheets("TeamList") '< qualify sheet here
    .Cells.Rows(lngItem).EntireRow.Font.Strikethrough = True
    End With
    End If
    Next lngItem


    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Remove selected item from listbox
    By ChrisMattock in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2014, 08:36 AM
  2. how do I return a HIGHLIGHTED (not selected) item from a ListBox?
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 08:27 AM
  3. Change status of more than one item selected in Listbox
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-29-2012, 05:09 AM
  4. [SOLVED] Need selected item from listbox after double click
    By peterfarge@hotmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2006, 11:20 AM
  5. How to copy selected listbox item to sheet
    By michdan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1