ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Could we define series variables in one statement? (https://www.excelbanter.com/excel-programming/293013-could-we-define-series-variables-one-statement.html)

Together[_7_]

Could we define series variables in one statement?
 
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

--
Message posted from http://www.ExcelForum.com


Mark Rosenkrantz[_2_]

Could we define series variables in one statement?
 
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.

--
More Excel ? www.rosenkrantz.nl or
-------------------------------------------------------------------


"Together " wrote in message
...
Hi, I am a new user of VBA in excel.

I want to know whether we can define a series variables in one
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 into
another file. If I copy the data one by one, it will take me a lot
time. Are there some methods that I can copy several data satisfying
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 to
open and close the files. So I think that there should be some good
method to improve the code. Could you tell me? Thanks.


---
Message posted from
http://www.ExcelForum.com/





All times are GMT +1. The time now is 12:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com