Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
hsg hsg is offline
external usenet poster
 
Posts: 40
Default copy cell from file with variable name

I need to copy a cell value from file having name d:\....\file001.xls into
currently
open worksheet in cell E1. The value "001" is a sequence number existing in
current worksheet in cell C1.

The requirement is to copy one cell from file001.xls into E1, file002.xls
into E2 ... and so on. Corresponding numbers exist in C1, C2 .... etc.

i.e. if C10 is "015", then E10 will receive value from file015.xls.
Number in column C are in ascending order.

Is this possible?


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default copy cell from file with variable name

Hi,

Right click the sheet tab where you are going to copy the data to, view code
and paste this in and run it.

Sub sonic()
Dim Lastrow As Long
Dim Folder As String, CopyValue As String
Lastrow = Cells(Rows.Count, "C").End(xlUp).Row
Folder = "C:\" 'Change to your path
For Each c In Range("C2:C" & Lastrow)
Workbooks.Open Filename:=Folder & "File" & c.Value & ".xls"
CopyValue = Sheets("Sheet1").Range("A1").Value
ActiveWorkbook.Close False
c.Offset(, 2).Value = CopyValue
Next
End Sub

Mike
"hsg" wrote:

I need to copy a cell value from file having name d:\....\file001.xls into
currently
open worksheet in cell E1. The value "001" is a sequence number existing in
current worksheet in cell C1.

The requirement is to copy one cell from file001.xls into E1, file002.xls
into E2 ... and so on. Corresponding numbers exist in C1, C2 .... etc.

i.e. if C10 is "015", then E10 will receive value from file015.xls.
Number in column C are in ascending order.

Is this possible?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How a cell can be addressed with variable file-column? thegreeneyes Excel Discussion (Misc queries) 1 February 5th 08 02:33 PM
how to copy a cell in excell and paste in a txt file with macro Krishna_AJ Excel Discussion (Misc queries) 0 June 21st 07 09:51 PM
Variable in VLOOKUP and referencing a cell another file in excel Dave T at home Excel Worksheet Functions 1 August 9th 06 03:14 AM
COPY CELL WITH FILE REFERENCES IN EXCEL natelee78 Excel Discussion (Misc queries) 4 July 12th 05 02:15 PM
How do I copy data from a cell in one file to another? acraig New Users to Excel 1 February 15th 05 03:09 PM


All times are GMT +1. The time now is 11:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"