How to write vba code for this

lecet444

Board Regular
Joined
May 18, 2011
Messages
91
as you can see the formulas here, the file name in all the formulas is the cell (column B) to the left. I would like to implement a vb code that would automatically fill out the sheet with the filenames in the formulas


Excel Workbook
ABCDEFG
1DatePO NUMBERTOTALabcdefghijkl
2June 16, 20117418$ 3,179.75
3June 16, 20117419
4June 16, 20117420
5June 16, 20117421
6June 16, 20117422
7June 16, 20117423
8June 16, 20117424
Raw Data

Excel 2010
Cell Formulas
RangeFormula
C2='F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$S$33
D2=IF(ISNA(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$C$16:$C$30,MATCH(D1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))),"",(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$C$16:$C$30,MATCH(D1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))))
E2=IF(ISNA(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418xls]PO'!$C$16:$C$30,MATCH(E1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))),"",(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$C$16:$C$30,MATCH(E1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))))
F2=IF(ISNA(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$C$16:$C$30,MATCH(F1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))),"",(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$C$16:$C$30,MATCH(F1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))))
G2=IF(ISNA(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$C$16:$C$30,MATCH(G1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))),"",(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$C$16:$C$30,MATCH(G1,'F:\Engineering\Michael\Excel\INVENTORY\PO\[7418.xls]PO'!$D$16:$D$30,0))))
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
i dont know where to begin wehter its a loop or what. I dont have any programming experience or excel for that matter, but I'm coming along
 
Upvote 0
If I understand your situation correctly, you don't need VBA. You can use Excel's Indirect function to build a cell reference based on strings.

So C2, for example, would be

Code:
 =Indirect("'F:\Engineering\Michael\Excel\INVENTORY\PO\[" & B2 & ".xls]PO'!$S$33")

Do the top row for each column then just copy down.
 
Last edited:
Upvote 0
thank you, but the reason i need vba is because the list of po numbers is always going to be changing. so I need the vba to match the number of rows, as they change. the list of po numbers changes based on a code, to call filter the po numbers by date
 
Upvote 0
thank you, but the reason i need vba is because the list of po numbers is always going to be changing. so I need the vba to match the number of rows, as they change. the list of po numbers changes based on a code, to call filter the po numbers by date
 
Upvote 0
Good morning all,

I am still having trouble with this code, if anyone could be kind enough to look into it, that would be great.


thank you
 
Upvote 0
It's only the file name you want? Not the path to?

Code:
Function FileNameOnly(rng As Range) As String
    Dim sFormula As String
    sFormula = rng.Formula
    FileNameOnly = Mid(sFormula, InStrRev(sFormula, "[") + 1, Len(sFormula))
    FileNameOnly = Mid(FileNameOnly, 1, InStr(FileNameOnly, "]") - 1)
End Function

This looks for the square brackets around the file name, and will only return the first file name found in a formula.
 
Upvote 0
My god, just used the Microsoft Excel Function Reference v4.0 book that's been sitting on my desk for the last six years.....

You could sent up a named range.
Call it something like 'CellFormula' and in the "Refers to:" box type
Code:
GET.FORMULA(A1)

This will return the formula of the referenced cell.
You can use this formula to extract the book reference:
Code:
=MID(CellFormula,FIND("[",CellFormula)+1,FIND("]",CellFormula)-FIND("[",CellFormula)-1)

Edit: May not be as fast as the VB code though as it references CellFormula 4 times.
 
Upvote 0
Hello, thank You very much

I will try this code asap. and The file path as well I needed, but I think i could figure that out. appreciate your input
 
Upvote 0

Forum statistics

Threads
1,224,578
Messages
6,179,654
Members
452,934
Latest member
mm1t1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top