Tengo un formulario que tiene 21 Columnas y mi Listbox 17 y no me deja...
Tengo un formulario en excel que tiene 21 columnas y un listbox con 17 columnas y cuando quiero incorpormas, me da error. Y no se que puedo hacer he visto ejemplos, no doy con la solución aquí dejo el código:
Private Sub CommandButton1_Click()
Dim lItem As Long, LbRows As Long, LbCols As Long
Dim bu As Boolean
Dim Lbloop As Long, Lbcopy As Long
LbRows = ListBox1.ListCount - 1
LbCols = ListBox1.ColumnCount - 1
For lItem = 0 To LbRows
If ListBox1.Selected(lItem) = True Then
bu = True
Exit For
End If
Next
If bu = True Then
With Sheets("MaterialienKopie").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For lItem = 0 To LbRows
If ListBox1.Selected(lItem) = True Then 'Row selected
'Increment variable for row transfer range
Lbcopy = Lbcopy + 1
For Lbloop = 0 To LbCols
'Transfer selected row to relevant row of transfer range
.Cells(Lbcopy, Lbloop + 1) = ListBox1.List(lItem, Lbloop)
Next Lbloop
End If
Next
For M = 0 To LbCols
With Sheets("MaterialienKopie").Cells(Rows.Count, 1).End(xlUp).Offset(0, M).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 23
End With
Next
End With
Else
MsgBox "nichts ausgewählt", vbCritical
Exit Sub
End If
MsgBox "Die ausgewählten Daten würden kopiert.", vbInformation
Sheets("MaterialienKopie").Select
End SubPrivate Sub UserForm_Initialize()
Sheets("Materialien").Activate
ligne = Range("A" & Rows.Count).End(xlUp).Row
Me.ListBox1.RowSource = "A2:R" & ligne
Label29.Caption = Sheets("MaterialienKopie").Range("W1")
Label29 = Format(Label29, " ##,###0.00 € ")
Dim lngMyHandle As Long, lngCurrentStyle As Long, lngNewStyle As Long
End Sub