I recorded a macro, which included selecting column(s) and setting the width. This worked until I made some changes in the preceding code, by editing in named ranges instead of the literal ranges recorded by the macro.
Now, the lines that select columns do not seem to be operating as expected. "Columns("A:A").Select" selects columns A:P!
It seems obvious to me that I introduced an error, but I'm not seeing it.
Sub DataImport()
Range("A10").Select
With ThisWorkbook.ActiveSheet.Range("Z1")
.Formula = "=VLookup(C5, FileNameDictionary, 3, False)"
.Value = .Value
End With
file_name = Range("Z1").Value
Range("z1").Value = ""
cx_name = "TEXT;" & Range("Cover!$C$18").Value & file_name
With ActiveSheet.QueryTables.Add(Connection:=cx_name, Destination:=Range("ResultGrid"))
.Name = ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("B:R").Select
Selection.ColumnWidth = 6
Columns("A:A").Select
Selection.ColumnWidth = 10
Range("A10").Select
HideEmptyRows
End Sub