0

I want to take some datas from another file in excel to come to my main file, I have no problem at all with this code:

Sub Call() ' ' Call Macro ' ' ActiveCell.FormulaR1C1 = _ "=IF(('C:\Users\prosp\Documents\Kabu\[Book1.xlsx]Sheet1'!R[1]C[-1])-('C:\Users\prosp\Documents\Kabu\[Book1.xlsx]Sheet1'!R[1]C[-4])=0,""0"",('C:\Users\prosp\Documents\Kabu\[Book1.xlsx]Sheet1'!R[1]C[-1])-('C:\Users\prosp\Documents\Kabu\[Book1.xlsx]Sheet1'!R[1]C[-4]))" Range("F4").Select End Sub 

But if the file's type change to .csv file, I can't call the datas which I want to use. The code was like this:

Sub Call() ' ' Call Macro ' ' ActiveCell.FormulaR1C1 = _ "=IF(('C:\Users\prosp\Documents\Kabu\[Book1.csv]Sheet1'!R[1]C[-1])-('C:\Users\prosp\Documents\Kabu\[Book1.csv]Sheet1'!R[1]C[-4])=0,""0"",('C:\Users\prosp\Documents\Kabu\[Book1.csv]Sheet1'!R[1]C[-1])-('C:\Users\prosp\Documents\Kabu\[Book1.csv]Sheet1'!R[1]C[-4]))" Range("F4").Select End Sub 

How can I call the .csv file with that code? Is there anyone who can help me please?

0

1 Answer 1

1

You need to import / convert the CSV file into Excel first. Otherwise you cannot access it with a formula. That is because a CSV file is just a text file with comma separated values like shown below:

Year,Make,Model,Length 1997,Ford,E350,2.34 2000,Mercury,Cougar,2.38 

A CSV file has no rows and columns like an Excel file that you can easily access. Therefore it has to be converted into an XLSX first. So it becomes:

 A B C D 1 | Year | Make | Model | Length | 2 | 1997 | Ford | E350 | 2.34 | 3 | 2000 | Mercury | Cougar | 2.38 | 

And now you can access it with a formula by its row and column.

So I suggest to open the CSV file and save it as XLSX first.
Also see VBA converting csv Files in a folder to xlsx Files.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.