• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Sending data from List Box - Msg box

Hi,

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.

Thanks
Seamus




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
0
Seamus2626
Asked:
Seamus2626
  • 2
  • 2
1 Solution
 
NorieCommented:
Try this, it assumes the listbox is single choice.

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

Open in new window

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

Thanks
Seamus
0
 
NorieCommented:
Why listbox1 and listbox2?

Did you try changing ListBox1 to ListBox2 in the code I posted?
0
 
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

0
 
Seamus2626Author Commented:
Have just done that.

Thanks
Seamus
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now