VBA Excel宏根据多个条件更新单元格值 [英] VBA Excel Macro to update cell values based on multiple criteria

查看:711
本文介绍了VBA Excel宏根据多个条件更新单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不可能解决这个问题,在我的沸点上限,所以我真的可以使用你的方向或帮助。我已经在标题中附加了一个图像。我需要一个vba宏来更新/更改列E(Ve Planning)中的值,具体如下:


  1. 列D必须为空。

  2. 必须仅在列A中更新相同的值。

  3. 列I(操作)= LASER。


然后用列E更新Operation = SUDURA的列E值操作价值LASER + 10天。





我不知道你是否理解这个混乱,但是如果你这样做,任何帮助都非常感激。



谢谢alot!

解决方案

尝试下面的短代码,它在我的测试中工作有限的数据记录。让我知道它是否适用于您的数据。

  Sub UpdateVEPlanning()


Dim sht As Worksheet
Dim LastRow,lRow As Long

'将Sheet1修改为您有
的任何工作表名称设置sht = ThisWorkbook.Worksheets(Sheet1)

'在数据表中找到最后一行
LastRow = sht.Cells(sht.Rows.Count,A)。End(xlUp).row

对于lRow = 2 To LastRow

如果sht.Cells(lRow,1)= sht.Cells(lRow - 1,1)然后
如果不是(sht.Cells(lRow,9 ).Find(SUDURA)Is Nothing)And(IsEmpty(sht.Cells(lRow,4).Value2)或sht.Cells(lRow,4).Value2 <= 0)Then
如果sht。单元格(lRow,6)= sht.Cells(lRow - 1,6)然后
sht.Cells(lRow,5)= sht.Cells(lRow - 1,5)+ 10
End If
如果
结束如果

下一个


End Sub


It is impossible for me to solve this, im at my boiling points upper limit, so i could really use your directions or help. I've attached an image in the header. I need a vba macro to update / change the values in column E ( Ve Planning ) with the following contitions:

  1. Column D must be blank.
  2. Must update only for the same values in column A.
  3. Column I ( Operation ) = LASER.
  4. If column F ( W NO ) values are equal.

Then update the column E value for Operation = SUDURA with column E value for operation LASER + 10 days.

I dont know if you understand this mess, but if you do, any help greatly appreciated.

Thanks alot!

解决方案

Try the short code below, it worked in my test with limited Data records. Let me know if it works on your data as well.

Sub UpdateVEPlanning()


Dim sht                                 As Worksheet
Dim LastRow, lRow                       As Long

' modify "Sheet1" to whatever worksheet name you have
Set sht = ThisWorkbook.Worksheets("Sheet1")

' find last row in sheet with data
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).row

For lRow = 2 To LastRow

    If sht.Cells(lRow, 1) = sht.Cells(lRow - 1, 1) Then
        If Not (sht.Cells(lRow, 9).Find("SUDURA") Is Nothing) And (IsEmpty(sht.Cells(lRow, 4).Value2) Or sht.Cells(lRow, 4).Value2 <= 0) Then
            If sht.Cells(lRow, 6) = sht.Cells(lRow - 1, 6) Then
                sht.Cells(lRow, 5) = sht.Cells(lRow - 1, 5) + 10
            End If
        End If
    End If

Next


End Sub

这篇关于VBA Excel宏根据多个条件更新单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆