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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:58:46  来源:igfitidea点击:

Excel VBA loop through columns in range and copy columns

excelvbaloopsexcel-vba

提问by RobDK

I am new to Excel VBA and need some help writing a macro.

我是 Excel VBA 新手,需要一些帮助来编写宏。

From Worksheet1of Workbook1I need to copy each column of range D1:Z100, one at a time, and pasteValue it to cells B1:B100.

Worksheet1ofWorkbook1我需要复制 range 的每一列D1:Z100,一次一个,然后将其 pasteValue 到 cells B1:B100

This triggers a calculation in Worksheet2of Workbook1. Here I need to copy cells A1:B200into a new workbook.

这触发了另一种计算Worksheet2Workbook1。在这里,我需要将单元格复制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:

以我们大多数人的方式开始:

  1. Record new macro.
  2. Manually perform all the steps you want to automate.
  3. Stop recording.
  4. Go to the Developer tab and inspect the auto-generated code.
  5. Write your own VBA based on what you learn in Step 4.
  1. 录制新宏。
  2. 手动执行您想要自动化的所有步骤。
  3. 停止录音。
  4. 转到“开发人员”选项卡并检查自动生成的代码。
  5. 根据您在第 4 步中学到的内容编写自己的 VBA。

You will have to figure out a few things on your own, or come back here and ask specific questions.

您必须自己弄清楚一些事情,或者回到这里提出具体问题。