简体   繁体   English

Excel VBA 将值添加到现有值而不是替换它?

[英]Excel VBA Adding the Value to the Existing Value instead of Replacing it?

I would like it if when it locates the coordinates, it adds the value in 'M19' to the existing value in the cell instead of replacing.我希望它在定位坐标时将“M19”中的值添加到单元格中的现有值而不是替换。 If anyone has a resolution to improving this code I would really appreciate the help.如果有人有改进此代码的决心,我将非常感谢您的帮助。 Thank you谢谢

Sub AddValue()
 
Dim row As String
Dim c As Single, r As Single
 
With Worksheets("Inventory")
 
    If .Range("M17").Value = "" Then Exit Sub
 
    row = .Range("M17").Value
 
    c = Application.Match(column, .Range("G5:G35"), 0)
    r = Application.Match(row, .Range("B5:B35"), 0)
 
    .Range("B4").Offset(r, c).Value = .Range("M19").Value
 
End With
End Sub

Simply简单地

.Range("B4").Offset(r, c).Value =.Range("B4").Offset(r, c).Value +.Range("M19").Value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM