Solved

Sending data from List Box - Msg box

Posted on 2012-03-22
5
241 Views
Last Modified: 2012-03-22
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
Comment
Question by:Seamus2626
  • 2
  • 2
5 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 37753255
Try this, it assumes the listbox is single choice.

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

Open in new window

0
 

Author Comment

by:Seamus2626
ID: 37753476
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
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 37753591
Why listbox1 and listbox2?

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

Expert Comment

by:DaFranker
ID: 37753637
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
 

Author Closing Comment

by:Seamus2626
ID: 37753647
Have just done that.

Thanks
Seamus
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need VBA code to create all combinations of a routing. 30 73
Excel 2010 Vlookup 4 27
Conditional fromatting formula 29 32
split data by day 21 32
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question