【发布时间】:2017-08-14 14:58:58
【问题描述】:
此代码是较大代码的一部分,它从列表框中获取单词并将其放入另一个列表框中,该代码使用此代码分隔列表框中的单词并建立成能够插入到单元格中的单词,出于某种原因第二个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的方式
- 项目1
- item2 item3 item4 ...
【问题讨论】:
-
请注意,如果您要嵌套循环,通常使用
j而不是ii作为内部 for 循环! -
vbLF代替vbCRLF会发生什么? -
@Jeeped 我听说 vbCrLf 在 Windows 上更好
-
工作表中的多行单元格使用换行符 (LF),而不是回车符 (CRLF)。 0x013 (CR) 字符通常会被删除,只留下 0x010 (LF) 字符。
-
我需要它,简而言之,转到下一行,想想,我应该这样做
vbNewline