Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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中行中突出显示的值对齐多列_Excel - Fatal编程技术网

如何根据excel中行中突出显示的值对齐多列

如何根据excel中行中突出显示的值对齐多列,excel,Excel,我有一个包含多个列的excel工作表,希望根据以黄色突出显示的值,将几个同名列对齐,例如column_ABC。每列都有一个高亮显示的值,因此将所有高亮显示的值面对面(同一行)。示例图像附带了输入数据和所需的输出数据。 注意:在计算结果之后,每列中的值将在上方或下方移动 多谢各位 这里有一个VBA选项。我对它进行了评论,以帮助理解。如果添加更多的列,这将起作用。如果列没有黄色突出显示,则将跳过该列 Sub test() Application.ScreenUpdating = False

我有一个包含多个列的excel工作表,希望根据以黄色突出显示的值,将几个同名列对齐,例如column_ABC。每列都有一个高亮显示的值,因此将所有高亮显示的值面对面(同一行)。示例图像附带了输入数据和所需的输出数据。 注意:在计算结果之后,每列中的值将在上方或下方移动

多谢各位


这里有一个VBA选项。我对它进行了评论,以帮助理解。如果添加更多的列,这将起作用。如果列没有黄色突出显示,则将跳过该列

Sub test()
    Application.ScreenUpdating = False
    Dim lRow, lCol, iRow, iCol As Long
    Dim wb As Workbook: Set wb = ThisWorkbook
    Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet1")
    Dim ReSort As Object: Set ReSort = CreateObject("Scripting.Dictionary")

    ' Find first empty cell in column A
    lRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    ' Find first empty column in row 2
    lCol = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column

    ' Loop through each filled column and row
    For iCol = 1 To lCol
        For iRow = 2 To lRow
            ' Find yellow
            If (Cells(iRow, iCol).Interior.Color = 65535) Then
                ' Store location of yellow highlight
                ReSort(iCol) = iRow
                ' Move rows in columns other than the first
                If iCol > 1 Then
                    ws.Range(Cells(2, iCol), Cells(100, iCol)).Cut Destination:=ws.Cells(ReSort(1) - ReSort(iCol) + 2, iCol)
                End If
            End If
        Next iRow
    Next iCol
    Application.ScreenUpdating = True
End Sub

@机修工,对不起。你没看见吗?我想我已经贴出来了。一张带有原始数据且为必填项的图像。您的问题没有VBA标记。您同意使用VBA解决您的问题吗?@Mech抱歉,如果可能,请仅使用excel。否则,VBA可能是一个选项。我知道您可以使用Excel按突出显示的颜色排序,但不能按您想要的方式排序。一个循环来查找高亮显示的对象,然后进行排序,这可能是您唯一的选择。@Mech好的。谢谢你的解决方案。我仍在等待一个更简单的解决方案。如果没有更多的答复,我将继续进行。