Function RunCode(TotalRows)
Dim SelectionString As String
Dim counter As Integer
SelectionString = "Selection.TextToColumns Destination:=ActiveCell, datatype:=xlFixedWidth, FieldInfo:=Array("
Do
If (counter = 0) Then
SelectionString = SelectionString & "Array(" & myArray(counter) & ", 2)"
Else
SelectionString = SelectionString & ", Array(" & myArray(counter) & ", 2)"
End If
counter = counter + 1
Loop Until (counter > TotalRows)
SelectionString = SelectionString & "), TrailingMinusNumbers:=True"
MsgBox (SelectionString)
'This string successfully produces the function to convert text in my selection to columns.
'However, SelectionString is a string obviously, and looks like the function I need, but I need a way to execute it.
'Or I need a different way to do this. The TotalRows changes each time, so I need a way to build this large 'FieldInfo' array dynamically
'NOTE: myArray is a global array, don't worry about what is in it.
End Function
|