Vba 用于将非空白单元格与中间的逗号组合在一起的函数
以下是经过改进并格式良好的函数:Vba 用于将非空白单元格与中间的逗号组合在一起的函数,vba,excel,Vba,Excel,以下是经过改进并格式良好的函数: Function COMBINE(rng As Range) Dim cell As Range Dim text As String For Each cell In rng Next cell If IsEmpty(cell.Value) Then Exit For Else: text = text & cell.Value & "," COMBINE = text End If End Function 不要只是扔掉一堆(未格式化的)代
Function COMBINE(rng As Range)
Dim cell As Range
Dim text As String
For Each cell In rng
Next cell
If IsEmpty(cell.Value) Then
Exit For
Else: text = text & cell.Value & ","
COMBINE = text
End If
End Function
不要只是扔掉一堆(未格式化的)代码——请问一个适当的问题<代码>对于每个…下一个循环将不产生任何结果,因为它是空的!您的代码无法按原样编译。如果您正确格式化了代码,您将立即看到For循环外部有一个出口。此外,For循环没有任何作用。我想IF语句应该进入For循环,但是,您将在范围中的第一个空白单元格处退出,因此如果在提供的范围中的空白单元格之后有其他连续的非空白区域,会发生什么情况?好的,应该是什么?
Function COMBINE(rng As Range)
Dim cell As Range
Dim text As String
For Each cell In rng
If IsEmpty(cell.Value) Then
Exit For
Else
text = text & cell.Value & ","
End if
Next cell
COMBINE = text
End Function