Hi Brett,
I wasn't sure how you wanted the user to select which columns to load into array(s), but maybe a start as to selecting which row to start on.
See attachment, but basic code is:
Option Explicit
Public lSkipLines As Long
Sub Main()
Dim FSO As Object
Dim fsoTFile As Object
Dim wbCSV As Workbook
Dim strFullName As String
Dim i As Long
'// Alter to suit - how many lines are previewed for user. //
Const NO_LINES_SHOWN As Long = 10
'// Optional, change to Drive and Directory the text file is expected to reside in. //
ChDrive Left(ThisWorkbook.FullName, 1)
ChDir ThisWorkbook.Path
strFullName = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt;*.csv), *.txt;*.csv", _
Title:="Select a TextFile", MultiSelect:=False)
'// In case user cancels //
If CStr(strFullName) = "False" Then Exit Sub
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fsoTFile = FSO.OpenTextFile(strFullName, 1, False, -2)
With fsoTFile
'// Load userform and add lines to
Load frmValidateSkipLines
For i = 1 To NO_LINES_SHOWN
frmValidateSkipLines.lstPreview.AddItem .ReadLine
Next
.Close
End With
frmValidateSkipLines.Show
If lSkipLines = 0 Then Exit Sub
If GetCSV(strFullName, lSkipLines, wbCSV) Then
MsgBox wbCSV.Sheets(1).Name
'// Load arrays etc
End If
End Sub
Function GetCSV(FName As String, SkipLines As Long, Optional WB As Workbook) As Boolean
Dim wks As Worksheet
Dim strTemp As String
Set WB = Workbooks.Open(Filename:=FName, Format:=3, Origin:=xlWindows) 'xlWindows xlMSDOS
Set wks = WB.Worksheets(1)
strTemp = "1:" & SkipLines
With wks
.Rows(strTemp).Delete
.UsedRange.NumberFormat = "General"
End With
strTemp = Mid(FName, InStrRev(FName, "\") + 1)
strTemp = Mid(strTemp, 1, InStrRev(strTemp, ".") - 1)
WB.SaveAs Filename:=Left(FName, InStrRev(FName, "\")) & strTemp & ".csv", _
FileFormat:=xlCSV
If Not WB Is Nothing Then GetCSV = True
End Function
Mark