Sub Text_Exclude()
'_________________________________________________________________________________________________________________________
'USER DECIDES FILE PATH
'Text File created from the Active Sheet
'Columns you don't want to add to the text file should be added to the line Exclusion=split(,,,,)
'______________________________________________________________________________________________________________________
Dim FSTR As String, H As Long, ColumnN As Long, AR As Variant, Exclusion As Variant, _
Text_Path As String, Delimiter As String, Column_Offset As Long, T As Long, FS As Object, TXT As Object
Text_Path = Application.GetSaveAsFilename 'USER DECIDES FILE PATH
If Text_Path = vbNullString Or Text_Path = "False" Then
MsgBox ("No input detected. Ending script")
End
End If
Set FS = CreateObject("Scripting.FileSystemObject")
Set TXT = FS.CreateTextFile(Text_Path, True, True) 'Unicode text file and will overwrite
Delimiter = Chr(9) 'TAB used to delimit array elements
Exclusion = Split("C,D,E,F,G", ",") 'column letters you don't want to parse
With ActiveSheet.UsedRange 'Determine if excluded columns were offset to determine array pasring
If .Column = 1 Then
AR = .Value2
Else
AR = .Value2
Column_Offset = .Column - 1 'default value is 0
End If
End With
For T = LBound(Exclusion) To UBound(Exclusion) 'convert column letters to column numbers
Exclusion(T) = ActiveSheet.Range(Exclusion(T) & 1).Column - Column_Offset
Next T
For H = 1 To UBound(AR, 1)
For ColumnN = 1 To UBound(AR, 2)
If IsError(Application.Match(CStr(ColumnN), Exclusion, 0)) Then 'if column number doesn't exist in the exclusion array
If FSTR = vbNullString Then
FSTR = AR(H, ColumnN)
Else
FSTR = FSTR & Delimiter & AR(H, ColumnN)
End If
End If
Next ColumnN
TXT.WriteLine (FSTR)
FSTR = vbNullString
Next H
TXT.Close
End Sub