从字符之间提取数据
有一个类似的问题得到了回答,但实际上它不太有效。我不知道是否有更好的方法来完成我的任务。 例如,我需要提取“(”和第三个“,”之间的数据 $$ Data_out(3,47,0,40,0,0,2,8.01)
并让结果为 3,47,0
我将在下面添加我的内容已经尝试过了
Dim str As String
Dim openPos As Integer
Dim closePos As Integer
Dim midBit As String
ActiveSheet.Range("A2").Activate
Do While Range("A:A").Cells(i, 1).Value <> ""
On Error Resume Next
openPos = InStr(str, "(")
On Error Resume Next
closePos = InStr(str, ",0,")
On Error Resume Next
midBit = Mid(str, openPos + 1, closePos - openPos - 1)
extract_value = midBit
ActiveCell.Value = midBit
i = i + 1
Loop
there was a similar question answered but in practice it doesn't quite work. I don't know if there is a better way to accomplish my task.
I need to extract the data between "(" and the third "," for example$$ Data_out(3,47,0,40,0,0,2,8.01)
and having the result be 3,47,0
I will add below what I've tried
Dim str As String
Dim openPos As Integer
Dim closePos As Integer
Dim midBit As String
ActiveSheet.Range("A2").Activate
Do While Range("A:A").Cells(i, 1).Value <> ""
On Error Resume Next
openPos = InStr(str, "(")
On Error Resume Next
closePos = InStr(str, ",0,")
On Error Resume Next
midBit = Mid(str, openPos + 1, closePos - openPos - 1)
extract_value = midBit
ActiveCell.Value = midBit
i = i + 1
Loop
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不同的方法:
Different approach:
阅读一些 VBA 教程以掌握基础知识。
这是使用工作表函数
Substitute
的替代方法,该函数具有实例参数,以便您可以挑选出第三个逗号。Read some VBA tutorials to master the basics.
Here's an alternative which use the worksheet function
Substitute
which has an instance parameter so you can pick out the third comma.