Excel VBA - 复制过滤的值 [英] Excel VBA - copy filtered value

查看:120
本文介绍了Excel VBA - 复制过滤的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在每张工作簿1中的单元格A2中有数据,在工作簿2中有主数据

我想要宏复制workbook1的sheet1的单元格A2和goto workbook2以及autofilter字段5,其值从workbook1复制。然后复制除标题之外的数据,转到workbook1并将数据粘贴到columnA中最后一个可见单元格下面。然后转到sheet2从单元格A2复制数据并转到workbook2和autofilter field5以相同的方式复制和粘贴,重复任务直到最后一页。



我是VBA的新手并且正在努力学习,请你帮帮我。



非常感谢每一个小帮助。



我尝试过:



i试图将代码部分写入,但是我无法在过滤器中粘贴值,这些值是从工作簿1的sheet1的单元格A处理的。



代码是

Hi,

I have data in cell A2 in each sheet of workbook1 and master data in workbook2
I want macro to copy cell A2 of sheet1 of workbook1 and goto workbook2 and autofilter field 5 with values copied from workbook1. then copy the data except header, go to workbook1 and paste data below last visible cell in columnA. then go to sheet2 copy data from cell A2 and go to workbook2 and autofilter field5 copy and paste in same way, repeat the task till last sheet.

I,m very new to VBA and trying to learn, can you please help me.

every little help is much appreciated.

What I have tried:

i tried writting the codes in parts but I'm not able to paste values in filter which is coped from cell A of sheet1 of workbook1.

codes are

Sub Copy_Data()
Worksheets(ActiveSheet.Index + 2).Select
Range("A2").Copy

Workbooks("Current_Month_Data.xlsx").Sheets("Sheet1").Activate


End Sub

推荐答案

学习如何执行此类任务的最佳方法之一是使用Excel的宏记录功能。启动宏录制器,执行所需步骤,停止宏录制器。您现在可以编辑录制的代码并根据自己的要求进行修改。
One of the best ways to learn how to do tasks like this is to use the macro record feature of Excel. Start the macro recorder, execute the steps you want, stop the macro recorder. You can now edit the recorded code and modify it as necessary for your own requirements.


看看这个提示:使用VBA在Excel表格之间复制数据 [ ^ ]。使用解决方案#2并改变您的需求。
Take a look at this tip: Copy Data Between Excel Sheets using VBA[^]. Use solution #2 and change to your needs.


这篇关于Excel VBA - 复制过滤的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆