热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

简单复制/粘贴循环不适用于每个工作表-SimpleCopy/PasteLoopnotworkingoneachworksheet

Imtryingtoloopthroughalltheworksheetsinmyworkbook.Oneachsheet,Idliketocopyavalu

I'm trying to loop through all the worksheets in my workbook. On each sheet, I'd like to copy a value from one cell, and paste the value on a different cell in that worksheet, and then continue on through the workbook. The code I've written loops through all the worksheets but only performs the copy paste on the sheet its on when the macro is run...

我正在尝试遍历工作簿中的所有工作表。在每张工作表上,我想从一个单元格中复制一个值,并将该值粘贴到该工作表中的另一个单元格上,然后继续浏览工作簿。我编写的代码循环遍历所有工作表,但只在宏运行时在工作表上执行复制粘贴...

Sub CleanUp()

Dim ws as Worksheet

For Each ws in ThisWorkbook.Sheets
    Range("BB2").Copy Range("A1")
Next ws

End Sub

In actuality, I want to run a more complicated series of alterations, but I can't even get this to work right.

实际上,我想进行一系列更复杂的改动,但我甚至无法使其正常工作。

2 个解决方案

#1


1  

append the worksheet to each range:

将工作表附加到每个范围:

Sub CleanUp()

Dim ws as Worksheet

For Each ws in ThisWorkbook.Sheets
    ws.Range("BB2").Copy ws.Range("A1")
Next ws

End Sub

#2


2  

An alternative solution that could run faster:

可以更快运行的替代解决方案:

Sub CleanUp()

Dim ws as Worksheet

For Each ws in ThisWorkbook.Sheets
    ws.Range("A1").Value = ws.Range("BB2").Value
Next ws

End Sub

推荐阅读
author-avatar
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有