VBA宏:条件列填充

时间:2010-02-13 15:07:21

标签: excel vba excel-vba

我从昨天开始就一直在努力解决这个问题,但却无处可去,希望有人能告诉我光明

我有这个工作簿,其中我有以下两个要求:

1)如果用户在A栏输入一个值(即日期):在C栏中自动填写'2'的值

2)

a-如果用户在D列中输入正数(+)(例如:+100):'DEP'的值将自动填入“H”列

b-如果用户在D栏输入负数( - )(例如:-50):'WD'的值会自动填入“H”列。

再次作为指针将非常感激。

非常感谢

2 个答案:

答案 0 :(得分:2)

不能使用常规公式吗?

H栏:= IF(VALUE(D1)> = 0,“DEP”,“WD”)

答案 1 :(得分:1)

Private Sub Worksheet_Change(ByVal Target As Range) 

Dim cell As Range 

On Error Goto ws_exit 

Application.EnableEvents = False 

If Target.Row > 1 Then 

    If Not Intersect(Target, Me.Columns(1)) Is Nothing Then 

        For Each cell In Target 

            cell.Offset(0, 2).Value = 2 
        Next cell 

    ElseIf Not Intersect(Target, Me.Columns(4)) Is Nothing Then 

        For Each cell In Target 

            If cell.Value > 0 Then 

                cell.Offset(0, 4).Value = "DEP" 
            Else 

                cell.Offset(0, 4).Value = "WD" 
            End If 
        Next cell 
    End If 
End If 
相关问题