Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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
在Excel VBA编辑器中发布的修剪参考文本_Vba_Excel - Fatal编程技术网

在Excel VBA编辑器中发布的修剪参考文本

在Excel VBA编辑器中发布的修剪参考文本,vba,excel,Vba,Excel,在此处输入代码我的以下代码在处理过程中有点短,因此我试图从.txt文件中获取文本以显示在Excel的单元格中,代码将 Sub citi() Dim c As Range Open "C:\Users\alvaradod\Desktop\citi macro\Import File.txt" For Input As #1 R = 0 Dim i As Range Dim num As Integer Dim arrData() As String the_value = Sheets("Prog

在此处输入代码
我的以下代码在处理过程中有点短,因此我试图从.txt文件中获取文本以显示在Excel的单元格中,代码将

Sub citi()
Dim c As Range
Open "C:\Users\alvaradod\Desktop\citi macro\Import File.txt" For Input As #1
R = 0
Dim i As Range
Dim num As Integer
Dim arrData() As String
the_value = Sheets("Prog").Range("A1")
Do Until EOF(1)
Line Input #1, Data
If Not Left(Data, 1) = "" Then
'import this row
R = R + 1
Cells(R, 1).Value = Data
'Mid(the_value, 3, 5)
'Left(Data, Len(Data) - 3)).Value
End If
Loop
For Each i In Range("A1")
i.Select
ActiveCell.Rows("1:1").Mid(Data(i), 49, 5).Select
'ActiveCell.Rows("1:1").EntireRow.Select
Selection.Copy
Sheets("Import").Range("A1").End(xlUp).Offset(num, 0).PasteSpecial
ActiveCell.Rows.Delete
 num = num + 1
Next i
端接头


“第11行将通过.TXT文件第一行的文本到EXCEL,完成此功能后,我需要在EXCEL工作表中修剪相同的文本,以显示前5个字符”

您的问题不是很清楚,但可能是这样的

Sub citi()

    Dim oFSO As Object
    Dim arrData() As String
    Dim arrImport1(1 To 65000) As String
    Dim arrImport2(1 To 65000) As String
    Dim i As Long, j As Long

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    arrData = Split(oFSO.OpenTextFile("C:\Test\test.txt").ReadAll, vbCrLf)

    For i = LBound(arrData) To UBound(arrData)
        If Len(arrData(i)) > 0 Then
            j = j + 1
            arrImport1(j) = Mid(arrData(i), 3, 5)
            arrImport2(j) = Mid(arrData(i), 49, 5)
        End If
    Next i

    If j > 0 Then
        Sheets("Sheet1").Range("A1").Resize(j).Value = Application.Transpose(arrImport1)
        Sheets("Sheet2").Range("A1").Resize(j).Value = Application.Transpose(arrImport2)
    End If

    Set oFSO = Nothing
    Erase arrData
    Erase arrImport

End Sub

如果我在一张工作表上有5行信息,每行大约30个字符,我想从位置34到40获取字符,那么该怎么做?感谢代码的使用。如果每行大约有30个字符长,并且您需要从位置34到40的字符,那么不会因为这些位置没有任何字符而返回空格吗?无论如何,您只需更改Mid函数
Mid(arrData(i),34,7)
对于下面的代码,我正在重新替换EntireRow。选择“第22行”作为“ActiveCell.Rows(“1:1”).Mid(Data(i),49,5)。选择“我可以看到您创建了一个重复的帖子”。你能用简单的英语一步一步地描述你想做什么吗?我有两个工作表(工作表1,工作表2),宏(代码)将转到文本文件(第3行)并将数据拉到工作表1(第10行),代码的下一步是使用mid()将每一行复制到工作表2函数从每行中对特定数量的字符进行子跟踪。(第21行)然而,我不认为第21行是正确的,我想听听你对此的看法。