将包含特殊字符的数字串提取出来,并按照列显示
时间:2011-08-10
来源:互联网
要求:
1、vlan之后的数字单独列在单元格中(每个数字一行)
2、碰见‘to’的,需要将之间的数据也增加列出,如,12 to 15,是指12、13、14、15
呈现结果:
vlan
511
619
620
621
.。。。。
请高手帮帮忙,谢谢。
作者: jickson 发布时间: 2011-08-10
Sub test()
'
' test Macro
'
Dim sum1 As Integer, i As Integer, j As Integer, sta As Integer, end1 As Integer
'Cells(1, 2) = InStr(1, Cells(1, 1), " ")
sta = 1
sum1 = start1 + 1
Cells(3, 1) = sum1
end1 = InStr(sum1, Cells(1, 1), " ")
Cells(1, 3) = Mid(Cells(1, 1), 1, end1 - sta)
Cells(2, 2) = end1
j = Len(Cells(1, 1))
For i = 2 To 100
sta = end1
Cells(i, 5) = sta
end1 = InStr(sta + 1, Cells(1, 1), " ")
Cells(i, 4) = end1
'sum1 = sta + 1
'end1 = InStr(sum1, Cells(1, 1), " ")
Cells(i, 3) = Mid(Cells(1, 1), sta + 1, end1 - sta)
'i = i + 1
if sta > j
then Cells(i, 3) = Mid(Cells(1, 1), sta + 1, j - sta)
End If
Next i
' star1 = InStr(1, Cells(1, 1), " ")
' sum1 = start1 + 1
' end1 = InStr(sum1, Cells(1, 1), " ")
' Cells(i, 2) = Mid(Cells(1, 1), i, Cells() - Cells())*/
'
End Sub
提示‘编译错误 ,语法错误’
作者: jickson 发布时间: 2011-08-10
a = Split(s)
Dim b(1 To 1000, 1 To 1)
For i = 1 To UBound(a)
If a(i) = "to" Then
For j = a(i - 1) + 1 To a(i + 1)
n = n + 1
b(n, 1) = j
Next
i = i + 1
Else
n = n + 1
b(n, 1) = a(i)
End If
Next
[a1].Resize(n) = b
作者: Zamyi 发布时间: 2011-08-10
作者: jickson 发布时间: 2011-08-10
代码:
Dim str$, arr(), i&, j&, s&, yReDim arr(1 To 10000, 1 To 1)
str = "vlan 511 619 to 621 662 1401 1403 to 1418 1499 to 1502 1510 to 1513 1515 to 1516 1600 1602"
y = Split(str, " ")
For i = 0 To UBound(y) - 1
If y(i + 1) <> "to" Then
s = s + 1: arr(s, 1) = y(i)
Else
For j = Val(y(i)) To Val(y(i + 2))
s = s + 1: arr(s, 1) = j
Next j
i = i + 2
End If
Next i
If y(UBound(y) - 1) <> "to" Then arr(s + 1, 1) = y(UBound(y))
Range("a1").Resize(s + 1, 1) = arr
作者: dsmch 发布时间: 2011-08-10
s = "vlan 511 619 to 621 662 1401 1403 to 1418 1499 to 1502 1510 to 1513 1515 to 1516 1600 1602"
For Each c In Range(Mid(Replace(Replace(Mid(s, 5), " to ", ":A"), " ", ",A"), 2)).Rows
i = i + 1
Cells(i, 1) = c.Row
Next
作者: Zamyi 发布时间: 2011-08-10
作者: jickson 发布时间: 2011-08-10
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28