# read Excel file by VBA?



## al_samirr (Nov 28, 2006)

I have excel file consist of two columns.
I want to read its cells and store it into variables (for each row)
please help


----------



## Jimmy the Hand (Jul 28, 2006)

Hi, and welcome to TSG forum.

The info you gave is not enough to give an exact solution to your question.
However, a general one might help you as well. So, in general, you can use the code below.
All that are in italic characters are to be replaced with the names and values you use.


```
[I]variablename[/I] = Workbooks("[I]workbookname[/I]").Sheets("[I]sheetname[/I]").Cells([I]rowindex, columnindex[/I]).Value
```
Also, if you want to refer to a cell of current workbook, current sheet, you can use simply

```
[I]variablename[/I] = Activesheet.Cells([I]rowindex,columnindex[/I]).Value
```
E.g. to store value of cell "C2" of the current sheet in variable "A" you need

```
A = Activesheet.Cells(2, 3).Value
```
For more help, please provide more info about what you need.


----------



## al_samirr (Nov 28, 2006)

Thank you very much
That's it
I benefited from your help.

thanks again


----------



## Zack Barresse (Jul 25, 2004)

al_samirr,

It is not even clear the context to which you're talking about. For your benefit - and others who search this board - would you mind explaining in detail what it is you are talking about?


----------



## Rollin_Again (Sep 4, 2003)

You may also want to explore the option of putting the values into an array instead of using seperate variables for each row of data.

Rollin


----------

