简体   繁体   English

嗨! 如何根据条件复制特定的数据行并将其粘贴到同一工作表的新列中,并在它们之间留有空白列

[英]Hi! How can I copy specific rows of data based on criteria and paste those to a new column on the same worksheet with a blank column between them

enter image description here Excel spreadsheet 在此处输入图像描述 Excel电子表格

Criteria for moving rows are based on column A = "Advia 1800 2" and column B = "15941". 行的移动条件基于列A =“ Advia 1800 2”和列B =“ 15941”。

If criteria are met, then copy and paste these rows to column I on the same worksheet under the headings as in the attached picture. 如果符合条件,则将这些行复制并粘贴到同一工作表下标题下的I列中,如所附图片所示。

I really appreciate if someone can show me what the macro will look like. 如果有人可以告诉我该宏的外观,我将非常感激。

  1. You also have an additional friend and that one is Macro Recorder. 您还有另外一个朋友,那个是Macro Recorder。 You can start recording your actions by selecting Record Macro It can be selected from Views->Macros-> Record Macro in Views Tab or in Developer Tab in code section or by clicking its symbol near bottom left corner side of your worksheet. 您可以通过选择“记录宏”来开始记录动作,可以从“视图”选项卡或“代码”部分的“开发人员”选项卡中的“视图”->“宏”->“记录宏”中进行选择,或者单击工作表左下角附近的符号。

  2. Now after clicking record macro, a popup appears and you can okay it after either noting macro name or change it to new one. 现在,单击“录制宏”后,将出现一个弹出窗口,您可以在注意到宏名称或将其更改为新名称后将其保存。 Let us ignore shortcut key at this stage. 现在让我们忽略快捷键。

  3. Now Macro has started recording your actions do manually what you want to do. 现在,Macro已开始记录您的操作手动执行您想执行的操作。 Select Range to be filtered, Select Filter in Data Tab. 选择要过滤的范围,在数据选项卡中选择过滤器。 Apply criteria from drop downs in Column 1 and then in Column 2. Go to Special in Find and Select section drop down and select visible cells and then copy. 从第1列然后在第2列的下拉列表中应用条件。在“查找和选择”部分的下拉菜单中选择“特殊”,然后选择可见的单元格,然后复制。 Select I1 cell and Paste. 选择“ I1”单元格并粘贴。 Go to Data Tab and click Filter again. 转到数据标签,然后再次单击过滤器。 Now you will see results in the sheet as per your requirements. 现在,您将根据需要在工作表中看到结果。 Code generated by Macro recorder is: 宏记录器生成的代码是:

      Sub Macro5() ' ' Macro5 Macro ' ' Range("A1:G14").Select Selection.AutoFilter ActiveSheet.Range("$A$1:$G$14").AutoFilter Field:=1, Criteria1:= _ "Advia 1800 2" ActiveSheet.Range("$A$1:$G$14").AutoFilter Field:=2, Criteria1:="15941" Selection.SpecialCells(xlCellTypeVisible).Select Selection.Copy Range("I1").Select ActiveSheet.Paste Application.CutCopyMode = False Selection.AutoFilter End Sub 

Results are shown in the snapshot. 结果显示在快照中。

结果

Still no reason to cheer as it has select statements. 仍然没有理由欢呼,因为它具有选择语句。 Please go through How to avoid using Select in Excel VBA macros as an exercise for you and modify the code to remove select in macro. 请仔细阅读如何避免在Excel VBA宏中使用“选择”作为练习,然后修改代码以删除“选择”在宏中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用VBA复制带有公式的列并将这些值粘贴到同一确切的列中? - How can I copy a column with formulas and paste those values in the same exact column using VBA? 如何将具有特定数据列的每周工作表复制到新工作表上 - How to copy a weekly worksheet with a specific column of data onto a new worksheet 我想复制工作表“ Prime Data”上的A列中的所有行,并使用代码粘贴到工作表“ Pime-Tracking”上的A列中 - I want to copy all rows from column A on worksheet “Prime Data” and paste into column A on worksheet “Pime - Tracking” with a code Excel VBA将数据粘贴到新工作表中与条件相关的列 - Excel VBA to paste data to a criteria-dependent column in new worksheet 根据条件将单元格从特定列复制到另一个工作表 - Copy cells from a specific column to another worksheet based on criteria 复制列中的特定单元格并粘贴到另一个工作表中 - Copy specific cell in column and paste in another worksheet 如何基于特定列而不是可变行中单元格的值命名工作表,同时创建/复制工作表? - How can I create/copy a worksheet while naming it based on the value of a cell in a specific column but variable row? 将具有NULL列的数据行复制到同一工作表中的另一个范围 - copy data rows with NULL column to another range in the same worksheet Excel VBA:如何根据条件读取列数据和删除工作表 - Excel VBA: How to read Column data and delete Worksheet based on criteria 使用两个列条件将数据转移到新工作表 - Transposing data to a new worksheet with two column criteria
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM