Excel VBA 循环遍历范围内的列并复制列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15357809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA loop through columns in range and copy columns
提问by RobDK
I am new to Excel VBA and need some help writing a macro.
我是 Excel VBA 新手,需要一些帮助来编写宏。
From Worksheet1
of Workbook1
I need to copy each column of range D1:Z100
, one at a time, and pasteValue it to cells B1:B100
.
从Worksheet1
ofWorkbook1
我需要复制 range 的每一列D1:Z100
,一次一个,然后将其 pasteValue 到 cells B1:B100
。
This triggers a calculation in Worksheet2
of Workbook1
. Here I need to copy cells A1:B200
into a new workbook.
这触发了另一种计算Worksheet2
的Workbook1
。在这里,我需要将单元格复制A1:B200
到一个新的工作簿中。
This new workbook is to be renamed with the text string in Worksheet1
, cell B1
. The new workbook is to be saved into the same folder as Workbook1
.
此新工作簿将使用Worksheet1
, cell 中的文本字符串进行重命名B1
。新工作簿将保存到与Workbook1
.
The loop is then to continue with the next column from Worksheet1
, and continue until all columns in the range have been treated this way.
然后循环从 继续处理下一列Worksheet1
,并继续直到范围内的所有列都以这种方式处理。
I have used two days searching the net to find an answer without any luck....
我已经用了两天的时间在网上搜索找到答案,但没有任何运气....
回答by nunzabar
Start the way most of us did:
以我们大多数人的方式开始:
- Record new macro.
- Manually perform all the steps you want to automate.
- Stop recording.
- Go to the Developer tab and inspect the auto-generated code.
- Write your own VBA based on what you learn in Step 4.
- 录制新宏。
- 手动执行您想要自动化的所有步骤。
- 停止录音。
- 转到“开发人员”选项卡并检查自动生成的代码。
- 根据您在第 4 步中学到的内容编写自己的 VBA。
You will have to figure out a few things on your own, or come back here and ask specific questions.
您必须自己弄清楚一些事情,或者回到这里提出具体问题。