Results 1 to 2 of 2

Thread: Excel/VB

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    2

    Excel/VB

    Hi, I wish to create a list box that can have multiple values selected and then copied into another worksheet seperated by commas. I have some code below and it's not working. Any help is appreciated.

    VB Code:
    1. Private Sub Worksheet_Change(ByVal Target As Range)
    2.     On Error Resume Next
    3.     Dim iLastRow As Long
    4.     Dim DropDown As Object
    5.     Dim i As Long
    6.     Dim j As Long
    7.     Dim k As Long
    8.     Dim l As Long
    9.    
    10.     j = 0
    11.     For k = 0 To ListBox17.ListCount - 1
    12.     If ListBox17.Selected(k) Then
    13.     Range("B9").Offset(j, 0) = ListBox17.List(k)
    14.     j = j + 1
    15.     End If
    16.     Next k
    17.    
    18.     l = ""
    19.     For k = 0 To ListBox17.ListCount - 1
    20.     If ListBox17.Selected(k) Then
    21.     l = l & ListBox17.List(k) & ","
    22.     End If
    23.     Next k
    24.     Range("F3") = l
    25.  
    26.  
    27.    
    28.  '   Dim j As Long
    29.    
    30.  '   For j = 1 To 15
    31.  '       Me.ListBox17.TopIndex = Me.ListBox17.ListCount - 1
    32.  '       Application.Wait Now + TimeSerial(0, 0, 1)
    33.  '   Next j
    34.  
    35.      
    36.     Set DropDown = ActiveSheet.Shapes("Drop Down 13").ControlFormat
    37.     i = DropDown.Value
    38.      
    39.     If Target.Address = "$B$19" Then
    40.         Application.EnableEvents = False
    41. On Error GoTo ws_exit:
    42.         With Worksheets("Bau")
    43.             iLastRow = .Range("B" & Rows.Count).End(xlUp).Row + 1
    44.             .Cells(iLastRow, "B").Value = Range("B1").Value
    45.             .Cells(iLastRow, "C").Value = Range("B4").Value
    46.             .Cells(iLastRow, "D").Value = Range("B5").Value
    47.             .Cells(iLastRow, "E").Value = Range("B7").Value
    48.             .Cells(iLastRow, "F").Value = ListBox.List(l)
    49.           '  .Cells(iLastRow, "F").Value = Range("B9").Value
    50.             .Cells(iLastRow, "G").Value = DropDown.List(i)
    51.             .Cells(iLastRow, "H").Value = Range("B13").Value
    52.             .Cells(iLastRow, "I").Value = Range("B15").Value
    53.             .Cells(iLastRow, "J").Value = Range("B17").Value
    54.             .Cells(iLastRow, "K").Value = Range("B19").Value
    55.             Range("B1:B21").ClearContents
    56.         End With
    57.     End If
    58.      
    59. ws_exit:
    60.     Application.EnableEvents = True
    61.     Exit Sub
    62. End Sub
    Last edited by si_the_geek; Oct 19th, 2005 at 06:19 PM. Reason: added VBCode tags for readability

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width