|
-
Dec 21st, 2009, 10:34 PM
#1
Thread Starter
Junior Member
[RESOLVED] List Box "nothing selected" Problem
I have a List Box that works fine except if nothing is selected the entire contents of the list box is automatically selected and imported. I'm looking for my code to display a custom message box if nothing is selected. I can get the message box portion to work fine when I change
If iListCount = -1 Then
frmMsgBox.Show
to
If iListCount = 0 Then
frmMsgBox.Show
but the first row of the list is never recognized and if I dont select anything and cancel the process it will still imports the first row ???
Been doing the trial/error thing and researching doing the for a couple of days with no success. Need the experts...
My Code:
Private Sub cmdStartImport_Click()
Dim iListCount As Integer
Dim iRow As Integer
Dim rStartCell As Range
Application.ScreenUpdating = False
Set rStartCell = Sheets("Log").Range("F1048576").End(xlUp).Offset(1, 0)
For iListCount = ListBox1.ListIndex To ListBox1.ListCount - 1
iRow = iRow + 1
rStartCell.Cells(iRow, 1).Value = ListBox1.List(iListCount, 0)
rStartCell.Cells(iRow, 2).Value = ListBox1.List(iListCount, 1)
rStartCell.Cells(iRow, 3).Value = ListBox1.List(iListCount, 2)
rStartCell.Cells(iRow, 4).Value = ListBox1.List(iListCount, 3)
'Is a row Selected
If iListCount = -1 Then
frmMsgBox.Show
Exit Sub
End If
Next iListCount
Set rStartCell = Nothing
Application.ScreenUpdating = True
End Sub
Thanks for any help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|