Import .csv file problem +

Mark Green

Board Regular
Joined
Apr 15, 2016
Messages
125
I got my lengthy VBA file working perfectly on Computer A.
Computer A has Excel 2002.

Just before I was going to send the file to my friend I decided to try the .xls
file on Computer B which has Excel 2013.

As luck would have it when I tried to run the macro I got a couple of errors.

The first error I got was when the first .csv import sub was run.
It stopped on the last line below.

Code:
Sub Prod_II_csv_import()

Application.ScreenUpdating = False

Dim file_name As String
Dim output_sheet As String
Dim row_number As String

    file_name = Sheets("RptAdmin").Range("B4").Value
    output_sheet = Sheets("RptAdmin").Range("C4").Value
    row_number = Sheets("RptAdmin").Range("D4").Value


  With Sheets(output_sheet).QueryTables.Add(Connection:= _
        "TEXT;" + file_name, Destination:=Sheets(output_sheet).Range("$A$" + row_number))
        .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 = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False     <------------------
    End With

End Sub

I have no idea why.

The second error I received occurred at the following line in my code:

Code:
Range("G8").Select    ' Total Profit calculated
ActiveCell.End(xlDown).Offset(1, 0).Select   <-----------------

In order to get the main part of my macro to run, I did the .csv import manually and then continued to run the macro from right after that part.

Here's the thing. If I commented out the .csv import, the macro stopped at the spot above:
ActiveCell.End(xlDown).Offset(1, 0).Select

However if I ran the macro manually (debug mode) after the manual .csv import, it did NOT stop at the line above!
It continued without any errors right to the end!

Any ideas or suggestions would be greatly appreciated!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Well I feel both stupid and greatly relieved!

The .csv import didn't work because I forgot to change the file directory path!

I just ran the macro now and it worked perfectly! :)

Not sure why that second error had cropped up.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,953
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top