如果单元格D包含在“MSD__CMT_Change”中,那么

时间:2012-08-27 14:50:22

标签: excel vba excel-vba

VBA代码将执行以下操作:

if cell = MSD_CMT_CHANGE then  

    compare cell above it if equal "MSD_CHANGE" then 

        cell E1 = E2.

我有超过5000行数据。

检查下面的图像以获得更好的解释。

sheet http://i49.tinypic.com/1enm7m.jpg

1 个答案:

答案 0 :(得分:2)

尝试这样的事情:

Sub Test
    Dim rng as Range, cl as Range

    Set rng = Range("D2:D" & Range("D" & Rows.Count).End(xlUp).Row)

    For each cl in rng
       If cl = "MSD_CMT_CHANGE" AND cl.Offset(-1, 0) = "MSD_CHANGE" Then
           cl.Offset(-1, 1) = cl.Offset(0, 1)
       End If
    Next cl
End Sub