Excel VBA从字符串打印子字符串
我想打印这个字符串中“…”之间的每个子字符串:“…covid…非常…可怕”,在excel的列中的连续单元格中 这是我在VBA中的代码Excel VBA从字符串打印子字符串,excel,vba,Excel,Vba,我想打印这个字符串中“…”之间的每个子字符串:“…covid…非常…可怕”,在excel的列中的连续单元格中 这是我在VBA中的代码 Sub copyd() findandcopy("...covid...is...very...scary") 'not sure how to print in consecutive cells of a column End Sub 有人能给我建议吗?谢谢你的帮助:)啊,为什么不把字符串拆分成“…” 比如: 它将返回一个字
Sub copyd()
findandcopy("...covid...is...very...scary") 'not sure how to print in consecutive cells of a column
End Sub
有人能给我建议吗?谢谢你的帮助:)啊,为什么不把字符串拆分成“…” 比如: 它将返回一个字符串数组,这些字符串是targetStr之间的位。然后,您可以在父sub中随心所欲地处理它 如果您开始与结果进行比较并发现问题,您可以通过修改上述内容来删除空白,如下所示:
substr(i) = trim(brokenstr2(i))
您的电话号码:
Sub main()
Dim covid as string
Dim remove as string
covid = "...covid...is....very...scary"
'covid = "really...covid...is...very...scary" 'For testing
remove = "..."
rtn = findandcopy(covid, remove)
end sub尝试以下代码:
Option Explicit
Sub copyd()
Dim arr As Variant
' get splitted text into horizontal array arr()
arr = Split("...covid...is...very...scary", "...")
If UBound(arr) > 0 Then ' if there is something in the array, display it on the sheet
' put onto sheet values from transposed array arr()
ThisWorkbook.Worksheets(1).Range("A1"). _
Resize(UBound(arr) + 1, 1).Value = _
WorksheetFunction.Transpose(arr)
End If
End Sub
看看
拆分
-命令-非常清楚!这是我调用函数的sub,但它给了我一个错误,表示ByRef参数类型不匹配:sub main()Dim covid,remove As String covid=“…covid…是…非常…可怕的”remove=“…”调用findandcopy(covid,remove)End Sub我可以知道为什么我调用函数是错误的吗?在两个单独的行上,Dim covid作为字符串&Dim remove作为字符串。在我的解决方案中也发现了输入错误,我选择stargetStr而不是targetStr。上文修正。我还将修改,以防split以substr(0)上的一个空条目开始
Sub main()
Dim covid as string
Dim remove as string
covid = "...covid...is....very...scary"
'covid = "really...covid...is...very...scary" 'For testing
remove = "..."
rtn = findandcopy(covid, remove)
Option Explicit
Sub copyd()
Dim arr As Variant
' get splitted text into horizontal array arr()
arr = Split("...covid...is...very...scary", "...")
If UBound(arr) > 0 Then ' if there is something in the array, display it on the sheet
' put onto sheet values from transposed array arr()
ThisWorkbook.Worksheets(1).Range("A1"). _
Resize(UBound(arr) + 1, 1).Value = _
WorksheetFunction.Transpose(arr)
End If
End Sub