Sure can, attached are a couple of the csv files, one with 2 test channels and one with 4.
When I run the code, the first part brings in the text just fine.
Dim strPath As String
Dim strFile As String
strPath = "C:\ont\"
strFile = Dir(strPath & "*.txt")
Do While strFile <> ""
With ActiveWorkbook.ActiveSheet
With .QueryTables.Add(Connection:="TEXT;" & strPath & strFile, _
Destination:=.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0))
.Parent.Name = Replace(strFile, ".txt", "")
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End With
strFile = Dir
Loop
The second part of the code is meant to search through and find the text "MocaTxBitRate" in column AP, and if true, insert 16 blank columns. Unfortunately it seems to insert 16 columns regardless of the conditions. So I know that the insert part works, the only issue seems to be not inserting if the condition is false. There is also probably a better way than just repeating the command 16 times, this seems a bit of a brute force method.
Columns("AP:AP").Select
Selection.Find(What:="MocaTxBitRate", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
If ActiveCell.Value = ("MocaTxBitRate") Then
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Else
Selection.Find(What:="MocaTxBitRate", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
End If
Thanks again, you have been a huge help. Excelforum is indeed the only place to go for help.
Bookmarks