我在 Excel 中有一个 VBA 函数从用户选择的单元格中返回一个连接的文本字符串。
这可以按我的要求工作,但是如果选择中有隐藏单元格,则包含隐藏单元格的值,这是不可取的。发生此问题的一个示例是筛选表时。
有没有办法修改我的函数来检查正在读取的单元格是否可见?
Sub ConcatEmialAddresses()
Dim EmailAddresses As String
ActiveSheet.Range("C3").Value = combineSelected()
ActiveSheet.Range("C3").Select
Call MsgBox("The email address string from cell ""C3"" has been copied to your clipboard.", vbOKOnly, "Sit back, relax, it's all been taken care of...")
End Sub
Function combineSelected(Optional ByVal separator As String = "; ", _
Optional ByVal copyText As Boolean = True) As String
Dim cellValue As Range
Dim outputText As String
For Each cellValue In Selection
outputText = outputText & cellValue & separator
Next cellValue
If Right(outputText, 2) = separator Then outputText = Left(outputText, Len(outputText) - 2)
combineSelected = outputText
End Function