Solved

Sending data from List Box - Msg box

Posted on 2012-03-22
5
237 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
Comment Utility
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
Comment Utility
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
Comment Utility
Why listbox1 and listbox2?

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

Expert Comment

by:DaFranker
Comment Utility
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
Comment Utility
Have just done that.

Thanks
Seamus
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now