My line of code looks this way
Worksheets("Calculator").Range("AB6:AB16", "AS7").Copy
.Cells(1, i).PasteSpecial Paste:=xlPasteValues
I want to be able to copy "AB6:AB16" and only the "AS7" cell. so my output would be AB6 AB7 AB8 AB9 AB10 and so forth until AB16 .. .. .. and lastly I just want to cell AS7..
My current situation is it copies, all the columns to AS, inclusive and my preferable output is the way its described above.
Prior to this one line of code, the output that I would get from 2 lines of code, one to copy "AB6:AB16" and another one to copy "AS7" just gave me wrong results (there is a rand() function that generates numbers that invoke a calculation in AS.
And I realized after trying various structures of the code, that the only time it copies the data correctly is when it happens in one line.
答案 0 :(得分:1)
正如我在您的评论中所理解的那样,您需要循环并在每次使用
之类的内容时进行更改Application.Calculation = xlCalculationManual
For i = 1 to 1000
With Worksheets("Calculator")
.Range("AB6:AB16").Copy .Cells(1, i).PasteSpecial Paste:=xlPasteValues
.Range("AS7").Copy .Cells(12, i).PasteSpecial Paste:=xlPasteValues
End with
Application.Calculate
Next i
Application.Calculation = xCalculationAutomatic
完全未经测试,但这个想法就在那里。
修改强>
如果您要循环列,请注意可用的列数,如果您循环10000次,则可能会耗尽您的excel版本(例如,2016年我认为有16384列。)
此外,如果您将“计算器”粘贴到同一张“计算器”中,则只要您在第28列中找到,就会覆盖rand()
功能。