I'm using index and match to find and return values inside a table which is inside a sheet ie not on it's own with column headings at the top ie the headings are down the sheet a bit hence the index and match to find the last date on two of the columns all of which works perfectly but ... when I try to put it into a loop macro to insert this index and match formula into thousands of similar sheets ( they're not all the same but all have the values in different places that I need to get ( which can be got with the index and match formula just copied and pasted into each sheet by hand )
The problem seems to happen because the formula has lost its references cos it's not in the sheet obviously.
Can anyone tell me if it is possible to insert this formula across thousands of workbooks using a vba macro or is there a better way to do it? ( I've managed to do it with a simple maths formula that just has straight cell ref like =E1+F1+G1 )
You'll be able to get the ref of the cell you're adding it to and calculate the relative cells to it.
Is it always the same i.e. column to right + etc?
Stanley Mc KeownOP
@Reply 2 years ago
No -- that's the problem hence index and match to find the column then find the last value in that column ( which is a date )
Stanley Mc KeownOP
@Reply 2 years ago
And the column starts halfway down the sheet
Stanley Mc KeownOP
@Reply 2 years ago
Though if you mean the destination workbook and sheet -- I can specify which cell to put the formula in so that I can look it up from access.
That was my original plan
1 copy the formula to the sheet I need the info on.
2 formula finds the column and last value on it
3 I know exactly where the value is now so get it to access some method.
There maybe some way the formula ( index and match which works no problem when it's anywhere in the sheet ) or a formula or code can be done directly from access.
I have a Loop macro to open each file in turn and paste into a cell -- only thing is I can't do it with that index and match formula. It's like excel is trying to resolve the formula even though I want to paste it as is. ( ie it's inside quotation marks so you'd think it should see it as a string )
Stanley Mc KeownOP
@Reply 2 years ago
I changed the cell references to absolute ie with $ signs in front and that works now when doing the job manually. Also I used a recorded macro ( while doing it manually ) which also works but only because both sheets are open and I get a load of warnings about circular references etc.
Stanley Mc KeownOP
@Reply 2 years ago
I sorted the problem by taking the mountain to Mohammed ie copying the range involved on the data sheet (that's another problem I had to solve see below) to the "formula sheet" workbook with the formula already in a cell far enough to the right to be well clear of getting pasted over.
I had trouble finding ( counting ) the number of columns cos the last column had a heading cell which was merged with 3 more columns to the right of it so it wouldn't see the last column and return a count which was one less than it should be.
I solved that by creating temporarily a second sheet ( sheet 2 ) in the data workbook and pasting the values on sheet 1 with number formats only to sheet 2 then pasting that to the "formula sheet in the formula workbook.
Now nested within the the loop macro I can suck out all the last dates along with any other relevant information about that record entry from every workbook in my trusted folder automatically. They all get saved along with a foreign key in a new record set ready to import to access.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Excel Forum.