基本上,我試圖模仿使用代碼拆分和回收用於我的目的代碼的連接結果。但是,當腳本嘗試處理「Next T」idk時,我遇到了問題,但我已經表明它是一個Dim - Integer,而且似乎還沒有成功。VBA:無效的下一步控制變量參考
的代碼原始來源: Concatenate multiple ranges using vba
我已經有很多的問題,這一塊,因爲它似乎是我實際上已經想在我的腳本中的唯一的事情現在已經很久了。有編譯錯誤關閉If,調整Then,甚至退出循環。
我認爲下一個應該是我最後的擔心。
順便說一句,rnumbers應該保留一個值/整數的位置,但我不完全確定這是否正確完成。
rnumbers = Rows(ActiveCell.Range("A3").End(xlDown)) + 3
'or CellCount = ActiveCell.Range("A" & Rows.Count).End(xldown).Row
Do While Rows(ActiveCell.Range("A3").End(xlDown)) > 3
'For Q = 1 To 10 'This provides a column reference to concatenate - Outer For statement
For T = 3 To rnumbers 'This provides a rows reference to concatenate - Inner for statement
For Each Cell In Cells("A" & T) 'provides rows and column reference
If Cell.Value = "" Then
GoTo Line1 'this tells the macro to continue until a blank cell is reached
Exit For
End If
x = x & Cell.Value & Chr(10) 'This provides the concatenated cell value and comma separator
'Next ' this loops the range
Next T 'This is the inner loop which dynamically changes the number of rows to loop until a blank cell is reached
Line1:
On Error GoTo Terminate 'Terminates if there are less columns (max 10) to concatenate
ActiveCell.Value = Mid(x, 1, Len(x) - 1) 'This basically removes the last comma from the last concatenated cell e.g. you might get for a range 2,3,4, << this formula removes the last comma to
'give 2,3,4
ActiveCell.Offset(1, 0).Select 'Once the concatenated result is pasted into the cell this moves down to the next cell, e.g. from F1 to F2
x = "" 'The all important, clears x value after finishing concatenation for a range before moving on to another column and range
'Next Q 'After one range is done the second column loop kicks in to tell the macro to move to the next column and begin concatenation range again
'rnumbers = 0
'Next
Exit Do
'Resume
Terminate:'error handler
感謝您抽出寶貴時間來評論和協助我的麻煩。您提出的第一條評論,關於下一條評論和活動。原來,這是一個額外的下一個,我評論說,爲了幫助腳本在沒有任何編譯錯誤的情況下流動,我留下了那條評論,讓我想起了所做的更改和調整。特別是當我回頭看時,有助於我的進步和矯正技能的提高。我也將變量從T更改爲'rcell',這也引發了相同的錯誤。我發佈了其餘的腳本。任何其他想法? – user2988769