【发布时间】:2014-03-08 17:18:56
【问题描述】:
基本上,我正在尝试使用为了我的目的而剥离并回收的代码来模拟连接结果。但是当脚本尝试处理“Next T”idk 时我遇到了问题,但我已经指示为 Dim - Integer,但这似乎仍然没有解决问题。
原始代码来源: 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
【问题讨论】:
标签: vba excel compiler-errors concatenation