Excel 循环搜索列,如果在该列的某个单元格中找到值,则将该值添加到同一行上相邻单元格中已有的值中
范例 VBA循环宏在单元格C2中找到值,因此它将该值添加到同一行单元格A2中的值,从而使单元格A2的值为31,并清除单元格C2中的值Excel 循环搜索列,如果在该列的某个单元格中找到值,则将该值添加到同一行上相邻单元格中已有的值中,excel,vba,Excel,Vba,范例 VBA循环宏在单元格C2中找到值,因此它将该值添加到同一行单元格A2中的值,从而使单元格A2的值为31,并清除单元格C2中的值 A B C D 1 2 15 16 3 Dim searchRadius作为要搜索的单元格的整数半径(例如100x100) search=TextBox1.Value'将搜索设置为某物 y=1 x=2 对于y=1,搜索半径 如果单元格(y,x)=搜索然后 单元格(y,1)。值=单元格(y,1)。值+搜索 单元格
A B C D
1
2 15 16
3
Dim searchRadius作为要搜索的单元格的整数半径(例如100x100)
search=TextBox1.Value'将搜索设置为某物
y=1
x=2
对于y=1,搜索半径
如果单元格(y,x)=搜索然后
单元格(y,1)。值=单元格(y,1)。值+搜索
单元格(y,x)。选择
单元(y,x)=“
如果结束
如果y=搜索半径和x
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