【发布时间】:2012-08-29 01:29:40
【问题描述】:
我对 VBA 编码真的很陌生。
我遇到的问题是:
B60、D60、F60、H60(等)单元格在此格式中具有不同的值:x、y、z (x、y 和 z 可以是数字 0-10) 我想把它拼接成:
B60 = x
B61 = y
B62 = z
D60 = x2
D61 = y2
D62 = z2
等等
我找到了这段代码:
Dim objRegex
Dim Z
Dim Y
Dim lngRow As Long
Dim lngCnt As Long
Dim tempArr() As String
Dim strArr
Set objRegex = CreateObject("vbscript.regexp")
objRegex.Pattern = "^\s+(.+?)$"
'Define the range to be analysed
Z = Range([a1], Cells(Rows.Count, "b").End(xlUp)).Value2
ReDim Y(1 To 2, 1 To 1000)
For lngRow = 1 To UBound(Z, 1)
'Split each string by ","
tempArr = Split(Z(lngRow, 2), ",")
For Each strArr In tempArr
lngCnt = lngCnt + 1
'Add another 1000 records to resorted array every 1000 records
If lngCnt Mod 1000 = 0 Then ReDim Preserve Y(1 To 2, 1 To lngCnt + 1000)
Y(1, lngCnt) = Z(lngRow, 1)
Y(2, lngCnt) = objRegex.Replace(strArr, "$1")
Next
Next lngRow
'Dump the re-ordered range to columns C:D
[a1].Resize(lngCnt, 2).Value2 = Application.Transpose(Y)
但这并不适合我。我只需要第 60 行就可以做到这一点。我真的尝试过编辑这段代码,但我什么都不懂……有人可以帮帮我吗?非常感谢。
【问题讨论】: