此代碼是較大代碼的一部分,它將一個列表框中的單詞從另一個列表框中放入另一個列表框中,該列表框使用此代碼將列表框中的單詞分隔開,並將其建立爲能夠成爲插入到一個單元格中,由於某種原因,第二個strsplt
沒有顯示,其他所有工作都很好,只是這一個,我需要幫助,沒有錯誤被拋出。我曾與F8和斷點看了過來,這個問題似乎與代碼跳過第二個單元格,不應該爲
If ii < .ColumnCount - 1 Then
str = str & .List(i, ii) & vbCrLf
Else
str = str & .List(i, ii)
End If
整個代碼:
With Me.selecteditems
ThisWorkbook.Sheets(9).Range("A:B").ClearContents
For i = 0 To .ListCount - 1
If .Selected(i) Then
found = True
For ii = 0 To .ColumnCount - 1
ReDim strsplt(0 To i)
If str = "" Then
str = .List(i, ii) & vbCrLf
Else
If ii < .ColumnCount - 1 Then
str = str & .List(i, ii) & vbCrLf
Else
str = str & .List(i, ii)
End If
End If
Next ii
message = "How much" & vbCrLf & str & "?" & vbCrLf
title = "Amount"
defaultval = "1"
quantity = InputBox(message, title, defaultval)
strsplt = Split(str, "*")
End If
'On Error Resume Next
With ThisWorkbook.Sheets(9)
.Range("A" & (i + 1)).Value = strsplt(i)
.Range("B" & (i + 1)).Value = quantity
End With
'On Error GoTo 0
Next i
End With
編輯:它看起來像使用debug.print str
- 方式item1
- item2 item3 item4 ...
如果你想要嵌套你的循環,只需要把''''替代爲'ii'作爲循環的內部循環! – Jsleshem
'vbLF'與'vbCRLF'有什麼不同? – Jeeped
@Jeeped我聽說vbCrLf在Windows上更好 – MaxAttack102