不从列表框加载空单元格 VBA excel
Dosent load the empty cells from listbox VBA excel
我有一个 CommandButton 可以将结果从列表框 (lsbWarenausgang) 加载到 sheet (Tabelle5),但是该按钮会加载结果以及 excel table 中的所有空结果.
Private Sub CommandButton3_Click()
Dim lRw As Long
Dim iX As Integer, iY As Integer
For iX = 0 To lsbWarenausgang.ListCount - 1
If Me.lsbWarenausgang.Selected(iX) = True Then
With Tabelle5
lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
For iY = 0 To Me.lsbWarenausgang.ColumnCount - 1
.Cells(lRw, iY + 1).Value = Me.lsbWarenausgang.List(iX, iY)
Next iY
End With
End If
Next iX
End Sub
你的意思是这样的(未测试)?我假设如果该列表框行中有数据,第一列将始终被填充。
Private Sub CommandButton3_Click()
Dim lRw As Long
Dim iX As Integer, iY As Integer
Dim col As Long
For iX = 0 To lsbWarenausgang.ListCount - 1
col = 1
If Me.lsbWarenausgang.Selected(iX) = True Then
With Tabelle5
If Len(Trim(Me.lsbWarenausgang.List(iX, 0))) <> 0 Then
lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
For iY = 0 To Me.lsbWarenausgang.ColumnCount - 1
If Len(Trim(Me.lsbWarenausgang.List(iX, iY))) <> 0 Then
.Cells(lRw, col).Value = Me.lsbWarenausgang.List(iX, iY)
col = col + 1
End If
Next iY
End If
End With
End If
Next iX
End Sub
我有一个 CommandButton 可以将结果从列表框 (lsbWarenausgang) 加载到 sheet (Tabelle5),但是该按钮会加载结果以及 excel table 中的所有空结果.
Private Sub CommandButton3_Click()
Dim lRw As Long
Dim iX As Integer, iY As Integer
For iX = 0 To lsbWarenausgang.ListCount - 1
If Me.lsbWarenausgang.Selected(iX) = True Then
With Tabelle5
lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
For iY = 0 To Me.lsbWarenausgang.ColumnCount - 1
.Cells(lRw, iY + 1).Value = Me.lsbWarenausgang.List(iX, iY)
Next iY
End With
End If
Next iX
End Sub
你的意思是这样的(未测试)?我假设如果该列表框行中有数据,第一列将始终被填充。
Private Sub CommandButton3_Click()
Dim lRw As Long
Dim iX As Integer, iY As Integer
Dim col As Long
For iX = 0 To lsbWarenausgang.ListCount - 1
col = 1
If Me.lsbWarenausgang.Selected(iX) = True Then
With Tabelle5
If Len(Trim(Me.lsbWarenausgang.List(iX, 0))) <> 0 Then
lRw = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
For iY = 0 To Me.lsbWarenausgang.ColumnCount - 1
If Len(Trim(Me.lsbWarenausgang.List(iX, iY))) <> 0 Then
.Cells(lRw, col).Value = Me.lsbWarenausgang.List(iX, iY)
col = col + 1
End If
Next iY
End If
End With
End If
Next iX
End Sub