gpt4 book ai didi

vba - 如何分隔列中的所有字符串并将每个子字符串粘贴到其他列中? (通过 VBA)

转载 作者:行者123 更新时间:2023-12-04 21:09:23 24 4
gpt4 key购买 nike

现在我在A列中有这样的字符串:

aa-bb-cc-123

aa-bb-cc-345

aa-bb-cc-789

etc...

如何在 VBA 中用“-”分隔字符串并将每个子字符串粘贴到不同的列中?举个例子:
column W    column X    column Y    column Z

aa bb cc 123

aa bb cc 456

aa bb cc 789

任何帮助,将不胜感激!

最佳答案

您可以尝试以下代码:

Sub split_AtoW()

Dim x As Long, mydata
For x = 1 To Range("A65526").End(xlUp).Row 'x = first row here, so change to 2 if header row exists
mydata = split(Range("A" & x), "-") 'put data in column A into an array split by "-"
Range("W" & x).Resize(1, UBound(mydata) + 1).Value = mydata 'put data in the split array into W onwards
Next x

End Sub

关于vba - 如何分隔列中的所有字符串并将每个子字符串粘贴到其他列中? (通过 VBA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19229161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com