是否有宏可以有条件地将行复制到另一个工作表?
在 Excel 2003 中是否有宏或方法可以有条件地将行从一个工作表复制到另一个工作表?
我通过 Web 查询将 SharePoint 中的数据列表提取到 Excel 中的空白工作表中,然后我想将特定月份的行复制到特定工作表(例如,将 SharePoint 工作表中的所有 7 月数据复制到7 月工作表、从 SharePoint 工作表到 6 月工作表的所有 6 月数据等)。
示例数据
Date - Project - ID - Engineer
8/2/08 - XYZ - T0908-5555 - JS
9/4/08 - ABC - T0908-6666 - DF
9/5/08 - ZZZ - T0908-7777 - TS
这不是一次性的练习。 我正在尝试构建一个仪表板,以便我的老板可以从 SharePoint 中提取最新数据并查看每月结果,因此它需要能够始终执行此操作并干净地组织它。
Is there a macro or a way to conditionally copy rows from one worksheet to another in Excel 2003?
I'm pulling a list of data from SharePoint via a web query into a blank worksheet in Excel, and then I want to copy the rows for a particular month to a particular worksheet (for example, all July data from a SharePoint worksheet to the Jul worksheet, all June data from a SharePoint worksheet to Jun worksheet, etc.).
Sample data
Date - Project - ID - Engineer
8/2/08 - XYZ - T0908-5555 - JS
9/4/08 - ABC - T0908-6666 - DF
9/5/08 - ZZZ - T0908-7777 - TS
It's not a one-off exercise. I'm trying to put together a dashboard that my boss can pull the latest data from SharePoint and see the monthly results, so it needs to be able to do it all the time and organize it cleanly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果这只是一次性练习,作为一种更简单的选择,您可以将过滤器应用于源数据,然后将过滤后的行复制并粘贴到新工作表中?
If this is just a one-off exercise, as an easier alternative, you could apply filters to your source data, and then copy and paste the filtered rows into your new worksheet?
这是可行的:它的设置方式是我从直接窗格中调用它,但您可以轻松创建一个 sub() ,它将每月调用一次 MoveData,然后只需调用该 sub。
您可能需要添加逻辑以在全部复制后对每月数据进行排序
This works: The way it's set up I called it from the immediate pane, but you can easily create a sub() that will call MoveData once for each month, then just invoke the sub.
You may want to add logic to sort your monthly data after it's all been copied
这是另一个解决方案,它使用 VBA 的一些内置日期函数,并将所有日期数据存储在数组中进行比较,如果您获得大量数据,这可能会提供更好的性能:
Here's another solution that uses some of VBA's built in date functions and stores all the date data in an array for comparison, which may give better performance if you get a lot of data:
我手动执行此操作的方法是:
下面列出的是通过 VBA 执行此过程的代码。
它的优点是处理每月的数据部分而不是单独的行。 这可以更快地处理更大的数据集。
The way I would do this manually is:
Listed below is code to do this process via VBA.
It has the advantage of handling monthly sections of data rather than individual rows. Which can result in quicker processing for larger sets of data.
这是部分伪代码,但您会想要类似的东西:
This is partially pseudocode, but you will want something like: