-1

我在 A 列和 B 列中有值。A 列的值应该是通过/失败。如果 A 列的值从“失败”更改为“通过”,则 B 列的值应移至 C 列。

我的意思是说,如果值从 A 更改为 B,那么 B 应该移动到另一个单元格。

例如:

变更前:

Column A   Column B  Column C 

 Fail         123       -

 Pass          -        456

更改后:

Column A   Column B  Column C 

 Pass        -          123

 Fail        456         -

一旦更改了值,它应该会自动发生。我不想每次都运行这个宏。

感谢提前!

4

2 回答 2

1
Private Sub Worksheet_Change(ByVal Target As Range)
CR = Target.Address
SplitCR = Split(CR, "$")
CC = SplitCR(1)
CR = SplitCR(2)
If CC = "A" Then
    CellBValue = Range("B" & CR)
    CellCValue = Range("C" & CR)
    Range("B" & CR).Value = CellCValue
    Range("C" & CR).Value = CellBValue
End If
End Sub

将上面的代码粘贴到您的工作表中。

于 2013-07-27T14:00:04.400 回答
0

尝试将其放入 Sheet1 的 VBA 代码中

' Requirement: Let's say the data before change looks like this:
' Column A -- Column B -- Column C
' Fail           123          -
' Pass            -          456
'
' After change of column A, data should look like this:
' Column A -- Column B -- Column C
' Pass            -          123
' Fail           456          -
'
Private Sub Worksheet_Change(ByVal Target As Range)

    ' Do calculations only if the target of change is 1st column (i.e. column A)
    If Target.Column = 1 Then

        ' Let's remember the data that's already in Column B and Column C
        Dim DataInColumnB, DataInColumnC As String
        DataInColumnB = Range(Replace(Target.Address, "A", "B")).Value
        DataInColumnC = Range(Replace(Target.Address, "A", "C")).Value

        ' We assume that if A has Pass, dash will be in column B
        ' and if A has Fail, dash will be in column C
        ' If we find that A has Pass but B is not a dash, we must swap information in B and C
        ' Similarly if A has Fail but C is not a dash, we must also swap information in B and C
        If (LCase(Target) = "pass" And DataInColumnB <> "-") Or _
        (LCase(Target) = "fail" And DataInColumnC <> "-") Then

            Range(Replace(Target.Address, "A", "B")).Value = DataInColumnC
            Range(Replace(Target.Address, "A", "C")).Value = DataInColumnB

        End If

    End If

End Sub
于 2013-07-27T14:03:56.400 回答