簡體   English   中英

Excel VBA將結果復制到For循環中,並將其粘貼到僅包含數字的新工作表中

[英]Excel VBA copy the results in a For loop and paste it into a new sheets with numbers only

我對VBA還是很陌生,我嘗試編寫一個段落以將結果復制到For循環中,然后將其粘貼到僅包含數字的新表中。

Range(Cells(42, 1), Cells(86, 20)).Select
Selection.Copy
Sheets("output").Select
b = 1 + 35 * a
Range(Cells(b, 1), Cells(b + 32, 20)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

可以執行該代碼,但是新工作表中的輸出為空。 將有20個多個空白塊被復制到新表中。 發送幫助!!!

嘗試這個:

b = 1 + 35 * a    

Range(Cells(42, 1), Cells(86, 20)).Copy 'consider using sheet reference here, like below :)
Sheets("output").Range(Cells(b, 1), Cells(b + 44, 20)).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

首先,我照顧了范圍,因此它們的尺寸匹配。

其次,強烈建議不要使用 SelectSelection 像我一樣使用引用。 這也增加了代碼的可讀性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM