ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For each picked entitiy in a list box... (https://www.excelbanter.com/excel-programming/356621-each-picked-entitiy-list-box.html)

Ctech[_115_]

For each picked entitiy in a list box...
 

Hi I have never used a list box, with VBA before..

How do i do it when the list box can have several marked choices...

i want my macro to add text is certain cells, depending on what i
picked of the list in the list box.

Thans

--
Ctec

-----------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...fo&userid=2774
View this thread: http://www.excelforum.com/showthread.php?threadid=52472


[email protected]

For each picked entitiy in a list box...
 
Hi
If you have a form called myForm with a multiselection listbox called
myListbox then

With myForm.mylistBox
'Get the selected data in the ListBox
For i = 0 To .ListCount - 1
'for each Group in the list
If .Selected(i) Then
'do your thing here
End If
Next i
End With

regards
Paul


Ctech[_117_]

For each picked entitiy in a list box...
 

For i = 0 To .ListCount - 1


on this part of the code I get 'run time error "424", - Objec
required'

Does this mean I missing some kind of "references"

--
Ctec

-----------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...fo&userid=2774
View this thread: http://www.excelforum.com/showthread.php?threadid=52472


Tom Ogilvy

For each picked entitiy in a list box...
 
Do you have a userform named myform and a listbox on that userform named
mylistbox?

--
Regards,
Tom Ogilvy


"Ctech" wrote:


For i = 0 To .ListCount - 1


on this part of the code I get 'run time error "424", - Object
required'

Does this mean I missing some kind of "references"?


--
Ctech


------------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=524722



Ctech[_119_]

For each picked entitiy in a list box...
 

See code below:

I have a list box, named cboSecondary which is in Sheet "combo".
non of this is actuall yin a form.

Sub Update_task_part()
' This macro adds the tasks picked in the List Box and adds them to th
Tasks revenue part of the form
' Created by Christian Simonsen 21/03/06

Dim mRows As Long
Dim i As Long
Dim Msg As String

' hides/unhides the required rows depending on the number of task
picked
mRows = cboSecondary.Selected
mRows = 10 - mRows
Range("list_rev").Rows("" & mRows & ":10").EntireRow.Hidden = Tru


' Gets the task numbers for the rows
' With cboSecondary
' For i = 0 To .ListCount - 1
' If .Selected(i) Then
' Msg = Msg & .List(i) & vbCrLf
' End If
' Next i
' End With

' If Len(Msg) = 0 Then
' Msg = "No items selected"
' End If

' MsgBox Msg



End Su


--
Ctec

-----------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...fo&userid=2774
View this thread: http://www.excelforum.com/showthread.php?threadid=52472


Tom Ogilvy

For each picked entitiy in a list box...
 
This worked for me. I assume cboSecondary is a LISTBOX (not a combobox) with
the multiselect property set to True

Sub Update_task_part()
' This macro adds the tasks picked in the List Box and adds them to the
' Tasks revenue part of the form
' Created by Christian Simonsen 21/03/06

Dim mRows As Long
Dim i As Long
Dim Msg As String

' hides/unhides the required rows depending on the number of tasks
' picked
mRows = 0
With cboSecondary
For i = 0 To .ListCount - 1
If .Selected(i) Then mRows = mRows + 1
Next
End With
Range("list_rev").EntireRow.Hidden = False
mRows = 10 - mRows + 1
Range("list_rev").Rows("" & _
mRows & ":10").EntireRow.Hidden = True


' Gets the task numbers for the rows
With cboSecondary
For i = 0 To .ListCount - 1
If .Selected(i) Then
Msg = Msg & .List(i) & vbCrLf
End If
Next i
End With

If Len(Msg) = 0 Then
Msg = "No items selected"
Else
MsgBox Msg
End If

End Sub

--
Regards,
Tom Ogilvy


"Ctech" wrote:


See code below:

I have a list box, named cboSecondary which is in Sheet "combo".
non of this is actuall yin a form.

Sub Update_task_part()
' This macro adds the tasks picked in the List Box and adds them to the
Tasks revenue part of the form
' Created by Christian Simonsen 21/03/06

Dim mRows As Long
Dim i As Long
Dim Msg As String

' hides/unhides the required rows depending on the number of tasks
picked
mRows = cboSecondary.Selected
mRows = 10 - mRows
Range("list_rev").Rows("" & mRows & ":10").EntireRow.Hidden = Tru


' Gets the task numbers for the rows
' With cboSecondary
' For i = 0 To .ListCount - 1
' If .Selected(i) Then
' Msg = Msg & .List(i) & vbCrLf
' End If
' Next i
' End With

' If Len(Msg) = 0 Then
' Msg = "No items selected"
' End If

' MsgBox Msg



End Sub



--
Ctech


------------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...o&userid=27745
View this thread: http://www.excelforum.com/showthread...hreadid=524722



Ctech[_121_]

For each picked entitiy in a list box...
 

Im still getting the same error "424, Object required"..

--
Ctec

-----------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...fo&userid=2774
View this thread: http://www.excelforum.com/showthread.php?threadid=52472


Ctech[_120_]

For each picked entitiy in a list box...
 

Im still getting the same error "424, Object required"..

--
Ctec

-----------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...fo&userid=2774
View this thread: http://www.excelforum.com/showthread.php?threadid=52472


Ctech[_123_]

For each picked entitiy in a list box...
 

Should I try to export the workbook to another computer and thest i
there

--
Ctec

-----------------------------------------------------------------------
Ctech's Profile: http://www.excelforum.com/member.php...fo&userid=2774
View this thread: http://www.excelforum.com/showthread.php?threadid=52472



All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com