Consulting

Results 1 to 4 of 4

Thread: Update Worksheet from Listbox selected items

  1. #1
    Banned VBAX Regular
    Joined
    Aug 2010
    Posts
    54
    Location

    Update Worksheet from Listbox selected items

    Can someone help me to get this working and perhaps tidy it up please - I need to update columns F and G of the selected Listbox items with data after an email has been sent.

    At the moment it's updating the last one selected but no others;

    Row = ListBox1.ListIndex + 2
    For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) = True Then
    Data = ListBox1.List(i, 2)
    TextBox1.Value = Data
    TextBox2.Value = Row
    SendEmail
    TextBox1.Value = ""
    End If
    Next i
    
    Select Case MsgBox("Do you want to mark these Records as Email Sent?", vbYesNo Or vbQuestion Or vbDefaultButton1, "Update email status")
    Case vbYes
    Row = ListBox1.ListIndex + 2
    For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) = True Then
    Sheets("Database").Range("F" & Row).Value = "Email Sent"
    Sheets("Database").Range("G" & Row).Value = Now()
    End If
    Next i
    
    
    Case vbNo
    
    End Select
    Posted elsewhere: http://www.mrexcel.com/forum/excel-q...ted-items.html

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Would changing & row to i + 1 help?

    Or, would you want to insert the selected values to the next blank row in those two columns?

  3. #3
    Banned VBAX Regular
    Joined
    Aug 2010
    Posts
    54
    Location
    Hi Kenneth - no, I need to update the row of the selected items so that when the Userform is displayed the next time those values don't appear, (I have a filter in place so that the Listbox only populates values where column F is blank).

    I don't know enough about changing it to your first line so will give that a go - it may well be that simple!

  4. #4
    Banned VBAX Regular
    Joined
    Aug 2010
    Posts
    54
    Location
    ' i + 1' does it so thank you!

Posting Permissions

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