Excel VBA 代码 - 查找一列中的值并将下一列中的数据移过
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18991891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA Code- Find Values in One Column and Move Data in Next Column Over
提问by user2812777
I am a bit new with VBA, but I am trying to find code which will search down column E, look for the values "TRUE", and for each one, move one cell to the right of this "TRUE" cell, and cut and paste it one cell to the right.
我对 VBA 有点陌生,但我正在尝试查找代码,该代码将向下搜索列 E,查找值“TRUE”,对于每个值,将一个单元格移动到此“TRUE”单元格的右侧,然后剪切并将其粘贴到右侧一个单元格。
I have been searching all day, and can't find a solution. Thank you in advance!
我已经搜索了一整天,但找不到解决方案。先感谢您!
回答by A.O.
Dim row
Dim column
Dim value
column = 5
For row = 1 To 5000 Step 1
value = Cells(row, column)
If value = "True" Then
Cells(row, column+1) = Cells(row, column)
Cells(row, column) = ""
End If
Next
This will search the first 1000 rows in the column, any cells that are true will be moved one cell to the right, obviously you need to declare Dim value
, row
and column
before the loop so that it will search the column you want.
这将搜索列中的前 1000 行,任何为真的单元格都将向右移动一个单元格,显然您需要声明 Dim value
,row
并column
在循环之前,以便它搜索您想要的列。