【发布时间】:2015-04-29 15:50:12
【问题描述】:
我有一张表,上面有类似的数据行。
NOM(LSL,USL)=207.3980(206.1990,208.5970) NOM(LSL,USL)=207.3980(206.1990,208.5970) NOM(LSL,USL)=18.8200(18.4400,19.2100)
我只想获取值并将它们放在自己的单元格中,例如
207.3980 207.3980 18.8200
206.1990 206.1990 18.4400
208.5970 208.5970 19.2100
我继续收到“ByRef 参数不匹配”错误。我相信与我如何定义参考单元格有关。
Sub Parse_Replace()
Dim i As Double
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
Dim Col As Range
Dim rLastCell As Range
Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
For i = rLastCell.Column To 1 Step -1
Col = ColLett(rLastCell.Column)
Columns(i).Cells(4) = SplitString(Col3, ",", 4)
Columns(i).Cells(5) = SplitString(Col3, ",", 5)
Columns(i).Cells(6) = SplitString(Col3, ",", 6)
Next i
End Sub
Function ColLett(Col As Integer) As String
If Col > 26 Then
ColLett = ColLett((Col - (Col Mod 26)) / 26) + Chr(Col Mod 26 + 64)
Else
ColLett = Chr(Col + 64)
End If
End Function
Function SplitString(pValue As String, pChar As String, pIndex As Integer) As Variant
Dim YString As Variant
YString = Replace(Replace(Replace(Replace(pValue, " ", ""), "=", ""), "(", ","), ")", ",")
SplitString = Split(YString, pChar)(pIndex - 1)
End Function
流程
- 用数据确定列数
-
遍历每一列
将列索引转换为带有
ColLett的列用
SplitString设置单元格值
循环
谢谢
编辑: 将 SplitString 值替换为 inteded。
【问题讨论】:
-
您在哪一行收到错误消息?
-
Columns(i).Cells(4) = SplitString(B3, ",", 4) -
是否可以假设 NOM(LSL,USL) 文本在所有行中都不相同?
-
@Jeeped,所有列都一样
标签: parsing excel replace split vba