vba 根据是否包含特定字符移动单元格的全部内容-Excel 2007

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18993568/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:29:33  来源:igfitidea点击:

Move entire contents of cell based on whether it contains a specific character-Excel 2007

excel-vbaexcel-2007vbaexcel

提问by user12059

I want to create a macro in Excel 2007 to search Column A for a colon (:) and if found, move the entire cell value into the same row Column B. Thus it my data looks like this:

我想在 Excel 2007 中创建一个宏来搜索 A 列中的冒号 (:),如果找到,则将整个单元格值移动到同一行 B 列中。因此,我的数据如下所示:

Column A     Column B
1:256   
13.049 
1:200    
1:100   
1:200   
1:512   
> 1:512 
13.909
1:100   
1:512   
1:512   
16.610

And to look like this post running macro:

并且看起来像这个运行宏的帖子:

Column A    Column B
            1:256   
13.049 
            1:200     
            1:100   
            1:200      
            1:512   
            > 1:512 
13.909
            1:100   
            1:512        
            1:512   
16.610

Ideas anyone?

任何人的想法?

采纳答案by Sathish Kothandam

Its always good to show your work here ..

在这里展示您的作品总是很好..

try to show your work hereafter but i help you this time

以后尝试展示您的作品,但这次我会帮助您

TESTED - Working fine

测试 - 工作正常

Sub tested()

Dim rng As Range
Dim lrow As Integer

With ActiveSheet
lrow = .Range("A" & Rows.Count).End(xlUp).Row

For Each rng In .Range("A2:A" & lrow)

If InStr(rng.Value, ":") > 0 Then

rng.Offset(0, 1).Value = rng.Value
rng.Value = ""
End If

Next rng

End With

End Sub