Hi,
I am trying to write a macro to extract data from some files. I have ~300 files and I want to take values, always from the same cells, from all of them for comparison. Obviously I'd rather not do this manually...
The file names are ordered like CeO2a_A_B with A and B always increasing by 1. Originally I wrote this:
This works fine for giving me the values for this one file however to get the data from the other files I'd have to copy, paste then manually change the name for each one (10211, 10212, 10213 etc.). To get round this I've put the code in a loop like this:
How do I get the macro to reference the right q and w values? I've tried every variation on - "CeO2a" & Format(q) & "_" & Format(w) & ".dat" - that I can think of but it doesn't work.
What is the correct syntax to do this? I suppose that I have to change "ActiveCell.Value" or the formatting of the file name, but I've no idea which.
Thanks a Lot,
John
I am trying to write a macro to extract data from some files. I have ~300 files and I want to take values, always from the same cells, from all of them for comparison. Obviously I'd rather not do this manually...
The file names are ordered like CeO2a_A_B with A and B always increasing by 1. Originally I wrote this:
For x = 4 To 4
Cells(x, 5).Select
ActiveCell.Value = "=CeO2a_1_10210.dat!R172C8"
Cells(x, 6).Select
ActiveCell.Value = "=CeO2a_1_10210.dat!R179C8"
Cells(x, 7).Select
ActiveCell.Value = "=CeO2a_1_10210.dat!R184C8"
Cells(x, 8).Select
ActiveCell.Value = "=CeO2a_1_10210.dat!R188C8"
Cells(x, 9).Select
ActiveCell.Value = "=CeO2a_1_10210.dat!R193C8"
Next x
This works fine for giving me the values for this one file however to get the data from the other files I'd have to copy, paste then manually change the name for each one (10211, 10212, 10213 etc.). To get round this I've put the code in a loop like this:
q = 1
w = 10210
For x = 4 To 23
Cells(x, 5).Select
ActiveCell.Value = "=CeO2a_q_w.dat!R172C8"
Cells(x, 6).Select
ActiveCell.Value = "=CeO2a_q_w.dat!R179C8"
Cells(x, 7).Select
ActiveCell.Value = "=CeO2a_q_w.dat!R184C8"
Cells(x, 8).Select
ActiveCell.Value = "=CeO2a_q_w.dat!R188C8"
Cells(x, 9).Select
ActiveCell.Value = "=CeO2a_q_w.dat!R193C8"
q = q + 1
w = w + 1
Next x
How do I get the macro to reference the right q and w values? I've tried every variation on - "CeO2a" & Format(q) & "_" & Format(w) & ".dat" - that I can think of but it doesn't work.
What is the correct syntax to do this? I suppose that I have to change "ActiveCell.Value" or the formatting of the file name, but I've no idea which.
Thanks a Lot,
John