I am trying to modify CuberChase's code on putting delimited string tables into a word document. As far as I know, his code has the rFromRange value being static (IE, hiding rows or columns is not accounted for).
I have tried changing the range to only be .SpecialCells(xlCellTypeVisible), but this ends up cutting the table short, rather than skipping the hidden rows/columns filtered out to still create the whole rest of the table. I have tried at length to figure out a solution by inserting vbCr and vbTab breaks on error, but I'm really not sure where to turn. Does anyone know how to set this array up to be able to skip columns or rows that end up being hidden on the original worksheet? Thank you for your time, please ask any additional questions for material that I have not covered here.
Function BuildDataString(rFromRange As Range) As String
Dim sData As String, nrRow As Long, nrCol As Integer, iTotalColumns As Integer
'Convert the input range to a variable and determine the number of columns
vData = rFromRange.Value
iTotalColumns = UBound(vData, 2)
'Loop through all the elements in the array
For nrRow = LBound(vData, 1) To UBound(vData, 1)
For nrCol = 1 To iTotalColumns
'Depending on what type of data is encountered either add it to the string or substitute something
'You'll want to modify this as needed
If IsError(vData(nrRow, nrCol)) Then
sData = sData & "Error"
ElseIf vData(nrRow, nrCol) = "" Or vData(nrRow, nrCol) = 0 Or vData(nrRow, nrCol) = "-" Then
sData = sData & VBA.Chr$(150)
Else
sData = sData & vData(nrRow, nrCol - iIncrement)
End If
'Use tab delimiters for Word to know where the columns are
If nrCol < iTotalColumns Then sData = sData & vbTab
Next nrCol
'Add a carriage return for each new line
If nrRow < UBound(vData, 1) Then sData = sData & vbCr
Next nrRow
'Return the completed string
BuildDataString = sData
End Function