循环搜索列,如果在该列的单元格中找到值,则将该值添加到同一行中相邻单元格中已有的值

时间:2016-07-10 01:47:24

标签: excel vba

实施例

      A    B    C    D
1
2     15        16
3

VBA循环宏在单元格C2中找到值,因此它将此值添加到同一行Cell A2中的值,从而生成Cell A2 31的值并清除Cell C2中的值

1 个答案:

答案 0 :(得分:0)

Dim y, x, search as Integer
Dim searchRadius as Integer    'Radius of Cells you want to search in (e.g. 100x100)

search = TextBox1.Value        'set search to something 
y = 1
x = 2

For y = 1 To searchRadius
    If Cells(y, x) = search Then
        Cells(y, 1).Value = Cells(y, 1).Value + search
        Cells(y, x).Select
        Cells(y, x) = ""
    End If
    If y = searchRadius and x <= searchRadius Then
        x = x + 1 
        y = 0
    End If
Next y

这对你有用吗?