Combining parts of filename and tabname in Excel cell

I have an Excel worksheet (attached) that I would like cell A30 to contain part of the filename and the entire tabname.

For example, the attached filename is DTL-EE-1711-Rev3.

I have successfully gotten EE-1711- to print in A30. Now I would like to add the Tabname to the cell so that the cell prints

EE-1711-02 in A30

For internal security reasons, I would prefer this is done with VBA instead of an Excel formula.

Obviously, by the end of the month, there will be Tabs 01, 02, 03, 04 ... through 30 or 31 skipping Saturday and Sunday.
DTL-EE-1711-Rev3.xlsm
LVL 1
Bill GoldenExecutive Managing MemberAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Try this:

=MID(CELL("filename",A1),SEARCH("[",CELL("filename",A1))+5, SEARCH("]",CELL("filename",A1))-SEARCH("[",CELL("filename",A1))-14)&MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)

Open in new window


»bp
0
Bill GoldenExecutive Managing MemberAuthor Commented:
Worked perfectly. Can we accomplish the same thing in VBA?

More questions coming regarding of features with the same spreadsheet.
0
Bill PrewCommented:
Sure in VBA, add this function, and then use it in a formula like:

=LogNumber()

Public Function LogNumber()
    a = Split(Split(ThisWorkbook.Name, ".")(0), "-")
    LogNumber = a(1) & "-" & a(2) & "-" & ThisWorkbook.ActiveSheet.Name
End Function

Open in new window


»bp
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Bill GoldenExecutive Managing MemberAuthor Commented:
Well that works for Tab 02 but does not work when you duplicate Tabs 03 and 04.

In addition while the worksheet is named

EE-1711-Rev2, occasionally it could be Rev2A. You can count on the YYMM appearing between the two dashes and that those will be the only two dashes.  We can force a 3-character lead like EEE-1711-RevX so that you could count on position 5 to be YY and position 7 to be MM.
0
Bill PrewCommented:
It worked okay for me on other sheets.

So, what are the rules on finding the "EE" and "1711" in the file name, being very specific?


»bp
0
Bill GoldenExecutive Managing MemberAuthor Commented:
I misspoke earlier. It is not working in Tab 02 (I forgot to remove the original formula from the cell. I think, but am not sure, that I was supposed to insert the cell number in the VBA code, but did see where to do so and put it in "This worksheet" so that it appears in every tab.

Am I confused?
0
Bill PrewCommented:
You didn't have to change the VBA at all, nor pass anything to it.  Here is a slightly tidier version that makes sure it gets the sheet name of the sheet the formula is on, just to be safe.  I also changed the way it gets the data to assume the parts you want are to the immediate left of the REV part, which is assumed to be last.  So anything else to the far left doesn't matter.  For example these work:

xxxxxxx-yyyyyyy-EE-1711-Rev1.xls
xxxxxxx-yyyyyyy-EE-1711-Rev1b.xls
xxxxxxx-EE-1711-Rev1.xls
EE-1711-Rev1.xls

Public Function LogNumber()
    a = Split(Split(ThisWorkbook.Name, ".")(0), "-")
    LogNumber = a(UBound(a) - 2) & "-" & a(UBound(a) - 2) & "-" & Application.Caller.Worksheet.Name
End Function

Open in new window


»bp
0
Bill GoldenExecutive Managing MemberAuthor Commented:
Well, I obviously am doing something in error adding the VBA code. I have attached a copy of the original spreadsheet with Tabs 02, 03 and 04 with the code added. None are working.
DTL-EE-1711-Rev4.xlsm
0
Bill PrewCommented:
You needed that VBA code in a new Module, not attached to a sheet.

And then you needed to add the formula to call it on each sheet in the cell you wanted it to appear in.

See attached.

DTL-EE-1711-Rev4.xlsm


»bp
0
Bill GoldenExecutive Managing MemberAuthor Commented:
Now I am getting something. But instead of EE-1711-01, I am getting EE-EE-01. Something I did?
0
Bill GoldenExecutive Managing MemberAuthor Commented:
By the way, using the same procedure, the TabDate routine (from the other question) works perfectly.  

Bill
0
Bill PrewCommented:
Sorry, cut and paste error, corrected version below.

Public Function LogNumber()
    a = Split(Split(ThisWorkbook.Name, ".")(0), "-")
    LogNumber = a(UBound(a) - 2) & "-" & a(UBound(a) - 1) & "-" & Application.Caller.Worksheet.Name
End Function

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill GoldenExecutive Managing MemberAuthor Commented:
Fabulous. That did the trick. Saves hours. Thanks again, more questions to come, Bill
0
Bill PrewCommented:
Very welcome Bill.


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.