Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
文本到列vba_Vba_Excel - Fatal编程技术网

文本到列vba

文本到列vba,vba,excel,Vba,Excel,如果使用了某个标题,我将尝试拆分一列。到目前为止,当我运行代码时,它会找到该列,将新列添加到右侧,更改标题,但随后会为“文本到列”部分抛出一个错误。我使用了record宏,然后对其进行了轻微更改 Sub CUSIPSymbol() Dim acell As Range Dim CCUSIP As Integer Set acell = Sheets("Fixed Income").Range("A1:Z4").Find(What:="CUSIP/ Symbol", LookIn:=xlValu

如果使用了某个标题,我将尝试拆分一列。到目前为止,当我运行代码时,它会找到该列,将新列添加到右侧,更改标题,但随后会为“文本到列”部分抛出一个错误。我使用了record宏,然后对其进行了轻微更改

Sub CUSIPSymbol()
Dim acell As Range
Dim CCUSIP As Integer

Set acell = Sheets("Fixed Income").Range("A1:Z4").Find(What:="CUSIP/ Symbol", LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
If Not acell Is Nothing Then
CCUSIP = acell.Column
Cells(1, CCUSIP + 1).EntireColumn.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
Cells(2, CCUSIP).Value = "CUSIP"
Cells(2, CCUSIP + 1).Value = "Symbol"
Columns(CCUSIP).TextToColumns Destination:=Range(Cells(1, CCUSIP)), DataType:=xlFixedWidth, _
    FieldInfo:=Array(Array(0, 1), Array(9, 1)), TrailingMinusNumbers:=True
End If

End Sub
获取以下错误


对象“”的方法“范围”全局失败

语法有问题吗

Sub CUSIPSymbol()
Dim acell As Range
Dim CCUSIP As Integer

Set acell = Sheets("Fixed Income").Range("A1:Z4").Find(What:="CUSIP/ Symbol", LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
If Not acell Is Nothing Then
CCUSIP = acell.Column
Cells(1, CCUSIP + 1).EntireColumn.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
Cells(2, CCUSIP).Value = "CUSIP"
Cells(2, CCUSIP + 1).Value = "Symbol"
Columns(CCUSIP).TextToColumns Destination:=Range(Cells(1, CCUSIP), Cells(100, CCUSIP)), DataType:=xlFixedWidth, _
    FieldInfo:=Array(Array(0, 1), Array(9, 1)), TrailingMinusNumbers:=True
End If

End Sub

根据Ann L.的建议,我在参考范围内添加了第二个单元格。我添加了一个远低于我预期的值的值,因此它将是灵活的。

错误消息是什么?对象的方法“范围”全局失败这不是我的专业领域,但是范围表达式不需要两个单元格引用吗?您在
TextToColumns
命令中指定的范围只有一个。此链接可能会有所帮助。这就解决了它!非常感谢。