Excel:在这种情况下如何使用 if?

Excel:在这种情况下如何使用 if?

我想使用工作表函数做类似以下的事情。

If cell (A1 = "ABC"), 
       then append to the begin of the cell B1 "ABC:" 
       and
       delete cell A1 and cell B1 becames A1, C1 -> B1 and so on

   else 
       append "" (or do nothing) - because in cell B2 I have already information

这可能吗?还是我需要 VBA?

答案1

显然,您不能使用简单的 if 语句在 excel 中执行此操作。您需要在 VBA 中执行此操作:

Public Sub StergeSTorOR()
Dim oRow As Range
Dim cell As Range
Dim i As Long, j As Long

    Application.ScreenUpdating = False

    For i = Selection(Selection.Count).Row To Selection.Cells(1, 1).Row Step -1

        For j = Selection(Selection.Count).Column To Selection.Cells(1, 1).Column Step -1

            If Cells(i, j).Value = "AB:" Or Cells(i, j).Value = "CD:" Then
                Cells(i, j + 1).Value = Cells(i, j).Value & Cells(i, j + 1).Value
                Cells(i, j).Delete shift:=xlShiftToLeft
                End If
        Next j
    Next i

    Application.ScreenUpdating = True
End Sub

相关内容