Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2365|回复: 2

[已解决]VBA怎么提取特定字符

[复制链接]
发表于 2015-1-28 21:01 | 显示全部楼层 |阅读模式
我有一个数据如下:
(-212.33,-33.02)|(-213.8,-36.118)
请问用VBA怎么一次提取提取出-212.33,-33.02,-213.8,-36.118这4个数据,并赋给a,b,c,d这4个变量?
谢谢!

最佳答案
2015-1-28 21:20

Sub test()
    Dim str$, arr
    str = "(-212.33,-33.02)|(-213.8,-36.118)"
    str = VBA.Replace(str, "(", "")
    str = VBA.Replace(str, ")", "")
    str = VBA.Replace(str, "|", ",")
    arr = VBA.Split(str, ",")
End Sub
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2015-1-28 21:20 | 显示全部楼层    本楼为最佳答案   

Sub test()
    Dim str$, arr
    str = "(-212.33,-33.02)|(-213.8,-36.118)"
    str = VBA.Replace(str, "(", "")
    str = VBA.Replace(str, ")", "")
    str = VBA.Replace(str, "|", ",")
    arr = VBA.Split(str, ",")
End Sub
回复

使用道具 举报

 楼主| 发表于 2015-1-28 21:55 | 显示全部楼层
爱疯 发表于 2015-1-28 21:20
Sub test()
    Dim str$, arr
    str = "(-212.33,-33.02)|(-213.8,-36.118)"

谢谢,我是这样搞的:
Sub test()
Dim arr
Dim ss
ss = .Cells(1, 1).Value
ss = Replace(Replace(Replace(ss, "(", ""), ")", ""), "|", ",")
arr = Split(ss, ",")
a = Val(arr(0))
b = Val(arr(1))
c = Val(arr(2))
d = Val(arr(3))
End With
End Sub

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 20:00 , Processed in 2.909190 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表