Sending data from List Box - Msg box


I have some code that sends data from ListBox2.

The code is below

If the user selects data from ListBox1 and presses the cmd button by mistake, they get my msbox MsgBox "Updated" where in fact no data was sent to the spreadsheet.

Can that message box only appear if there is actually data sent.


Private Sub SendingData_Click()
Dim NextCell As Range
Dim arrList
Application.ScreenUpdating = False
Application.DisplayAlerts = False

     Set NextCell = Workbooks("Match.xls").Worksheets("Mapping Table").Range("B" & Rows.Count).End(xlUp).Offset(1)

     NextCell.value = ListBox2.value
MsgBox "Updated"

End Sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Try this, it assumes the listbox is single choice.

If ListBox1.ListIndex <> -1 Then MsgBox "Nothing Selected":Exit Sub

Open in new window

Seamus2626Author Commented:
Thats not working for me Inmorie, have you any line that could say only give msgbox if  ListBox1+Listbox2 have been selected?

NorieAnalyst Assistant Commented:
Why listbox1 and listbox2?

Did you try changing ListBox1 to ListBox2 in the code I posted?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Frank WhiteCommented:
If it comes to that, you can always do:

If (ListBox1.ListIndex <> -1) Or (ListBox2.ListIndex <> -1) Then MsgBox "Missing Selection":Exit Sub

Open in new window

Seamus2626Author Commented:
Have just done that.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.