Could we define series variables in one statement?

  • Thread starter Thread starter Together
  • Start date Start date
T

Together

Hi, I am a new user of VBA in excel.

I want to know whether we can define a series variables in on
definition.

Such as:

Dim x(i) as integer

then, all the x(i), i=1,2,3.... is integer.

My situation is that I should copy several data in one file int
another file. If I copy the data one by one, it will take me a lo
time. Are there some methods that I can copy several data satisfyin
the condition to another file simulatenously.

my code is like these:

For i = 2 To 16

Workbooks.Open Filename:=DaSourceAfter & DaSourceFile 'open one file
Worksheets(1).Activate
totalvalue = Worksheets(1).Cells(i, 4).value
ActiveWorkbook.Close SaveChanges:=True

Workbooks.Open Filename:="D:\total\total.xls"
Worksheets(1).Activate
Worksheets(1).Cells(1, q) = DaSourceFile
Worksheets(1).Cells(p, q) = totalvalue

ActiveWorkbook.Close SaveChanges:=True
p = p + 1

Next i

Although I can copy the data to another file, it takes a lot time t
open and close the files. So I think that there should be some goo
method to improve the code. Could you tell me? Thanks
 
Hi there;

Maybe I understood you wrong, but as I read your text, I yhink you don't
need it.
I can't find any x in your code so why use x(i).

When you use Dim i as integer, al i's from 2 to 16 al declared as integer.
This to me is so straightforward that I wonder if I missed something.

Mark.
 
Back
Top