Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ListBox error "Invalid argument"
I get the above error in my code on line Me.ListBox2.Remove Item i. What I am
attempting to do is remove any item from the ListBox2 in excess of 25 Item. In other words, if the user attempts to place 26 or more items in the ListBox a message is display and the excess items are removed. This is my dilemma. Any help will be greatly appreciated. For i = 0 To ListBox1.ListCount - 1 If Me.ListBox1.Selected(i) = True And i <= 25 Then Me.ListBox2.AddItem ListBox1.List(i) ElseIf ListBox1.Selected(i) = True And i 25 Then MsgBox Msg, Style, Title Me.ListBox2.RemoveItem i Exit For End If Next i |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
ListBox error "Invalid argument"
On May 6, 9:42*am, Ayo wrote:
I get the above error in my code on line Me.ListBox2.Remove Item i. What I am attempting to do is remove any item from the ListBox2 in excess of 25 Item. In other words, if the user attempts to place 26 or more items in the ListBox a message is display and the excess items are removed. *This is my dilemma. Any help will be greatly appreciated. For i = 0 To ListBox1.ListCount - 1 * * * * If Me.ListBox1.Selected(i) = True And i <= 25 Then * * * * * * Me.ListBox2.AddItem ListBox1.List(i) * * * * ElseIf ListBox1.Selected(i) = True And i 25 Then * * * * * * MsgBox Msg, Style, Title * * * * * * Me.ListBox2.RemoveItem i * * * * * * Exit For * * * * End If * * Next i Ayo, I'm assuming your code is in the ListBox1_Click event. I'm also assuming that as the user selects an item from ListBox1, the item is populated into ListBox2. Once ListBox2 is populated to 25 items, you want an error message to fire letting the user know that ListBox2 is "full." You will find the code below to accomplish my stated assumptions. Best, Matthew Herbert Private Sub ListBox1_Click() Dim I As Integer 'fill ListBox2 and check if ListBox2 has 25 items With Me If ListBox2.ListCount <= 25 Then .ListBox2.AddItem .ListBox1.Value Else MsgBox Msg, Style, Title End If End With End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
ListBox error "Invalid argument"
Thanks. I was able to figure out what I needed to do was to add another For
loop: For i = 0 To ListBox1.ListCount - 1 If Me.ListBox1.Selected(i) = True And i <= 25 Then Me.ListBox2.AddItem ListBox1.List(i) ElseIf ListBox1.Selected(i) = True And i 25 Then MsgBox Msg, Style, Title For j = ListBox2.ListCount - 1 To 25 Step -1 ListBox2.RemoveItem j Next j Exit For End If Next i " wrote: On May 6, 9:42 am, Ayo wrote: I get the above error in my code on line Me.ListBox2.Remove Item i. What I am attempting to do is remove any item from the ListBox2 in excess of 25 Item. In other words, if the user attempts to place 26 or more items in the ListBox a message is display and the excess items are removed. This is my dilemma. Any help will be greatly appreciated. For i = 0 To ListBox1.ListCount - 1 If Me.ListBox1.Selected(i) = True And i <= 25 Then Me.ListBox2.AddItem ListBox1.List(i) ElseIf ListBox1.Selected(i) = True And i 25 Then MsgBox Msg, Style, Title Me.ListBox2.RemoveItem i Exit For End If Next i Ayo, I'm assuming your code is in the ListBox1_Click event. I'm also assuming that as the user selects an item from ListBox1, the item is populated into ListBox2. Once ListBox2 is populated to 25 items, you want an error message to fire letting the user know that ListBox2 is "full." You will find the code below to accomplish my stated assumptions. Best, Matthew Herbert Private Sub ListBox1_Click() Dim I As Integer 'fill ListBox2 and check if ListBox2 has 25 items With Me If ListBox2.ListCount <= 25 Then .ListBox2.AddItem .ListBox1.Value Else MsgBox Msg, Style, Title End If End With End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
ListBox error "Invalid argument"
I'm not sure what you're doing, but if you have an "ok, copy to listbox2"
button, you could check to see how many items are selected in listbox1 and if the number of items is 25, the button would be disabled. Add a message to a label and tell them to deselect some items. That way, they can make the choice of which ones to keep and which ones shouldn't be kept. If you want to try: Option Explicit Private Sub CommandButton1_Click() Dim iCtr As Long 'Me.ListBox2.Clear 'remove any previous entries??? With Me.ListBox1 For iCtr = 0 To .ListCount - 1 If .Selected(iCtr) Then Me.ListBox2.AddItem .List(iCtr) End If Next iCtr 'remove the choices from listbox1???? For iCtr = .ListCount - 1 To 0 Step -1 If .Selected(iCtr) Then .RemoveItem iCtr End If Next iCtr End With End Sub Private Sub CommandButton2_Click() 'cancel button Unload Me End Sub Private Sub ListBox1_Change() Dim iCtr As Long Dim HowManySelected As Long Dim MaxChoices As Long MaxChoices = 4 '25 when you're done testing HowManySelected = 0 With Me.ListBox1 For iCtr = 0 To .ListCount - 1 If .Selected(iCtr) = True Then HowManySelected = HowManySelected + 1 End If Next iCtr End With If HowManySelected 0 _ And HowManySelected <= MaxChoices Then Me.CommandButton1.Enabled = True Me.Label1.Caption = "" Else Me.CommandButton1.Enabled = False Me.Label1.Caption = "Please make between 1 and " _ & MaxChoices & " selections" End If End Sub Private Sub UserForm_Initialize() Dim iCtr As Long Me.Caption = "Pick items to move to Listbox2" With Me.ListBox1 .MultiSelect = fmMultiSelectMulti For iCtr = 1 To 30 .AddItem "A" & iCtr Next iCtr End With With Me.CommandButton1 .Caption = "Ok" .Default = True .Enabled = False End With With Me.CommandButton2 .Caption = "Cancel" .Cancel = True .TakeFocusOnClick = False .Enabled = True End With Me.Label1.Caption = "" End Sub Ayo wrote: I get the above error in my code on line Me.ListBox2.Remove Item i. What I am attempting to do is remove any item from the ListBox2 in excess of 25 Item. In other words, if the user attempts to place 26 or more items in the ListBox a message is display and the excess items are removed. This is my dilemma. Any help will be greatly appreciated. For i = 0 To ListBox1.ListCount - 1 If Me.ListBox1.Selected(i) = True And i <= 25 Then Me.ListBox2.AddItem ListBox1.List(i) ElseIf ListBox1.Selected(i) = True And i 25 Then MsgBox Msg, Style, Title Me.ListBox2.RemoveItem i Exit For End If Next i -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
"Compile Error: ByRef argument type mismatch" when calling my function from another module | Excel Programming | |||
Export to excel via webpage: "Invalid Procedure Call or Argument" | Excel Programming | |||
Pivot Table Creation Macro fails with Error #5 "Invalid procedure call or argument" | Excel Programming | |||
"ByRef argument type mismatch" Error | Excel Programming | |||
Invalid "format string" argument in Format fuction | Excel Programming |