Update Worksheet from Listbox selected items

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
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;

Code:
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
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,215,692
Messages
6,126,228
Members
449,303
Latest member
grantrob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top