Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.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,需要的脚本是重新排列单元格 以前 Human:Annie [Fruit]=Banana [Fruit]=Mango [Fruit]=Apple Human:Jack [Fruit]=Apple Human:John [Fruit]=Mango [Fruit]=Papay 之后 数据从1列更改为2列 之前:A列中的人类和水果数据 之后:A列中的人类数据和B列中的水果数据对不起,我的atm机上没有excel,只有excel starter,因此没有vba为您解决问题,但也许我可以让您开始。我将此作

需要的脚本是重新排列单元格

以前

Human:Annie
[Fruit]=Banana
[Fruit]=Mango
[Fruit]=Apple
Human:Jack
[Fruit]=Apple
Human:John
[Fruit]=Mango
[Fruit]=Papay
之后

数据从1列更改为2列 之前:A列中的人类和水果数据
之后:A列中的人类数据和B列中的水果数据

对不起,我的atm机上没有excel,只有excel starter,因此没有vba为您解决问题,但也许我可以让您开始。我将此作为答案发布,以便我可以格式化代码示例。希望这能帮助你开始。只是一个如何开始的提示。如果你不能把它分类,其他人可以稍后为你提供更好的答案

Sub MoveValue()
Dim i As Integer
Dim x As Integer

x = ActiveSheet.UsedRange.Rows.Count

With ActiveSheet
    For i = 2 To x
        If Instr(.Cells(i, 1),"Human:") = 1 Then
            .Cells(i, 2).Value = .Cells(i, 1).Value
        End If
        If Instr(.Cells(i, 2),"[Fruit]") = 1 Then
            .Cells(i, 3).Value = .Cells(i, 2).Value
        End If

    Next i
End With
端接头


这将留下空白行,我希望如此,正如我所说,这不是一个完整的解决方案。

argh,注释中不包含格式,我将在答案中添加注释,请不要选择我的答案。删除我的答案,因为它不是针对您的编辑。我从你的编辑中看出我不理解你的问题。您的数据来源是什么?“人类:”和“水果”是实际数据的一部分吗?看起来您应该只需要两列数据,一列标记为人类,另一列标记为水果。如果这是示例数据,那么如果您向我们展示实际数据,可能会有所帮助。所有数据中都包括人和[水果]。。我要分开那些数据
Sub MoveValue()
Dim i As Integer
Dim x As Integer

x = ActiveSheet.UsedRange.Rows.Count

With ActiveSheet
    For i = 2 To x
        If Instr(.Cells(i, 1),"Human:") = 1 Then
            .Cells(i, 2).Value = .Cells(i, 1).Value
        End If
        If Instr(.Cells(i, 2),"[Fruit]") = 1 Then
            .Cells(i, 3).Value = .Cells(i, 2).Value
        End If

    Next i
End With