I wanted to ask how to change the code below so it will ignore blank cells:
The UDF works great but I receive a "value" when all the cells in a range are all blank
The following code works and does not result in a "value", how do I change it by adding the following line?
Thank you in advance!!
The UDF works great but I receive a "value" when all the cells in a range are all blank
Code:
Function Concat(myRange As Range, Optional myDelimiter As String)
Dim r As Range
Application.Volatile
For Each r In myRange
If Len(r.Text) > 0 Then
Concat = Concat & Format(r, "000") & myDelimiter
End If
Next r
If Len(myDelimiter) > 0 Then
Concat = Left(Concat, Len(Concat) - Len(myDelimiter))
End If
End Function
The following code works and does not result in a "value", how do I change it by adding the following line?
Code:
Concat = Concat & Format(r, "000") & myDelimiter
Code:
Function Concat(rng As Range, Optional sep As String = ",") As String
Dim rngCell As Range
Dim strResult As String
For Each rngCell In rng
If rngCell.Value <> "" Then
strResult = strResult & sep & rngCell.Value
End If
Next rngCell
If strResult <> "" Then
strResult = Mid(strResult, Len(sep) + 1)
End If
Concat = strResult
End Function
Thank you in advance!!
Last edited by a moderator: