本文介绍了搜索字符串中的文本,复制&将行粘贴到新工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VBA编程的新手,我需要一些帮助,在Excel 2010中编写一个简单的宏。



我需要在列A中搜索一个文本字符串我正在搜索的确切文字是未指定),如果在单元格内找到该字符串,请将该单元格的整行剪切并粘贴到工作簿中的另一个工作表中删除原始工作表中的空行。



我在论坛上搜索过一些代码示例,几乎让我想要得到但不完全。

解决方案

好的。我使用录音机,并暗示你们都离开了我,并提出了这个宏。我没有使用增量器或循环,而是过滤它,并一直做到这一点。这个过程对我来说是有效的,现在我办公室里的每一个人都在做,所有人现在都认为我真的很擅长VBA,但事实并非如此,但我肯定是在这样做的:)



感谢大家,为了帮助!



Sub MoveNotSpec()



'主页上的未指定过滤器,剪切,将行粘贴到新表和删除主表上的空行

  Selection.AutoFilter 
ActiveSheet.Range(A1:A2000 ).AutoFilter字段:= 1,Criteria1:= _
= *指定*,运算符:= xlAnd
ActiveSheet.UsedRange.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
表单(OtherSheet)。选择
范围(A2)。选择
ActiveSheet.Paste
表格(FirstSheet)。选择
Application.CutCopyMode = False
Selection.Delete Shift:= xlUp
ActiveSheet.Range(A1:A2000)。AutoFilter字段:= 1
/ pre>

结束子


I am new to VBA programming, and I need some help writing a simple macro in Excel 2010.

I need to search for a text string in Column A (the exact text I'm searching for is not specified) and if that string is found within the cell, cut and paste that cell's entire row into another sheet in the workbook and then delete the empty rows in the original sheet.

I searched the forum a bit and found some code examples that almost got me where I wanted to get but not quite.

解决方案

OK. I used the recorder, and hints that you all left me, and came up with this macro. I'm not using an incrementor or looping it, but rather filtering it and doing it all in one go. This process has worked for me and now everyone in my office... and everyone now thinks I'm really good at VBA... which is NOT the case, but I'm certainly on my way :)

Thanks everyone, for the help!!!

Sub MoveNotSpec()

'Filters for "Not Specified" on main sheet and cuts, pastes rows into new sheet and deletes empty rows on main sheet'

Selection.AutoFilter
ActiveSheet.Range("A1:A2000").AutoFilter Field:=1, Criteria1:= _
    "=*specified*", Operator:=xlAnd
ActiveSheet.UsedRange.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("OtherSheet").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("FirstSheet").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
ActiveSheet.Range("A1:A2000").AutoFilter Field:=1

End Sub

这篇关于搜索字符串中的文本,复制&将行粘贴到新工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:37