Hi there,
I was wondering what I did wrongly.
I wanna run a loop so that it'll import all the .csv files onto different sheets in a workbook.
What i did is, I put a list of "names" in column A of sheet1, and told it to import the files with the SAME "names" from a specific folder, say "c:\comics" . However, I keep getting this error:
Run-time error '1004':
Excel cannot find the text file to refresh this external data range.
Check to make sure the text file has not been moved or renamed, then try the refresh again.
Here's the thing i did:
SO when I run it, it fails.. however, if I change the last line toDim count As Integer
Dim nama() As String
Dim j As Integer
count = Selection.Rows.count 'counting number of rows with names in them
ReDim nama(1 To count) 'specifying number of names to count above
For j = 1 To count Step 1
nama(j) = Range("sheet1!A2").Offset(j - 1, 0) 'Assigning names to variables "nama(j)" from column A of sheet 1
ActiveWorkbook.Worksheets.Add
With ActiveSheet.QueryTables.Add("TEXT;C:\Comics\" & nama(j) & ".csv" _
, Destination:=Range("A1"))
...
...
...
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
instead of nama(j), it'll run fine... Except that it'll just open 100 new sheets filled with comic1's data.With ActiveSheet.QueryTables.Add("TEXT;C:\Comics\Comic1.csv" _
, Destination:=Range("A1"))
Any help is appreciated. THanks in advanced
Bookmarks