excel - 找到ramdomly定位的值并返回左侧单元格中的值

时间:2016-11-10 21:43:56

标签: excel

我需要找到多个随机定位的值" windows_group"在名为" data"的工作表上并将单元格的值返回到" windows_group"的左侧。单元格到另一个工作表" Windows_Groups"。

工作表"数据"只有A-G列中的数据,但最多可包含5000行。

提前谢谢!

1 个答案:

答案 0 :(得分:1)

这样做可能会更优雅,但是蛮力方式将是循环遍历您的单元格并使用偏移方法的宏:

sub FindAndReturn() 'I'm not good at naming
dim cell as range
dim i as integer
dim k as integer
k = 1

for each cell in Worksheets("Data").Range("B1:G5000") ' i'm assuming this has to start in column B if you want the value to the left
     if cell.value = "windows_group" Then
          Worksheets("Windows_Groups").Range("A" & k).Value = cell.offset(0,-1).value
          k=k+1
     End if
next cell
end sub
相关问题