View Single Post
 
Old 07-08-2020, 06:29 PM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You could pass it to a funtion:
Code:
Sub TestATS()
Dim arrTest() As String
  arrTest = Split("A", "|")
  MsgBox fcnArrayToString(arrTest)
  arrTest = Split("A|B", "|")
  MsgBox fcnArrayToString(arrTest)
  arrTest = Split("A|B|C|D", "|")
  MsgBox fcnArrayToString(arrTest)
  MsgBox fcnArrayToString(arrTest, True)
End Sub

Public Function fcnArrayToString(varIn As Variant, Optional bOxford As Boolean = False) As String
Dim strTemp As String
Dim lngIndex As Long
  Select Case UBound(varIn)
    Case 0: fcnArrayToString = varIn(0)
    Case 1: fcnArrayToString = varIn(0) & " and " & varIn(1)
    Case Else
      fcnArrayToString = varIn(0)
      lngIndex = 1
      Do While lngIndex < UBound(varIn)
        fcnArrayToString = fcnArrayToString & ", " & varIn(lngIndex)
        lngIndex = lngIndex + 1
      Loop
      If bOxford Then
        fcnArrayToString = fcnArrayToString & ", and " & varIn(lngIndex)
      Else
        fcnArrayToString = fcnArrayToString & " and " & varIn(lngIndex)
      End If
  End Select
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote