Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

How to get tabs to change based on cell

0

I'm trying to get some tabs in my workbook to change depending on what is in a cell reference. The cells have formulas and sometimes show a blank cell in which case I would like the sheet to hide or just show mon?

I would like the following please.

Tab =    Cell

Mon1 = Cell E28

Mon2 = Cell J28

Mon3 = Cell L28

Mon4 = Cell N28

Mon5 = Cell P28

Mon6 = Cell R28

Mon7 = Cell E30

Mon8 = Cell J30

Mon9 = Cell L30

Mon10 = Cell N30

Mon11 = Cell P30

Mon12 = Cell R30

Answer
Discuss

Answers

0

Albert

Don't have much time but the code below (when placed behind  active worksheet "Cover") will rename the tabs to suit.

Private Sub TabNames()

Dim ws As Worksheet, Arr() As Variant

Arr = [{"$E$28","$J$28","$L$28","$N$28","$P$28","$R$28","$E$30","$J$30","$L$30","$N$30","$P$30","$R$30"}]

ThisWorkbook.Unprotect Password:="242200"

For n = LBound(Arr) To UBound(Arr)
    With Sheets(n + 3)
        .Unprotect Password:="242200"
        .Name = Format(Range(Arr(n)).Value, "mmm yy")
        .Unprotect Password:="242200"
    End With
Next n

ThisWorkbook.Unprotect Password:="242200"
End Sub

You just have to add a line test for nothing in the cell (and to hide that sheet)

Hope this helps.

Discuss

Discussion

Thanks John

I did what you said and if I run it it changes tabs. However if I change the start date to 1/2/22 then it doesn't change anything unless I run it again but doesn't hide the tabs.

Sorry I know nothing about MVB
wildecoyote1966 (rep: 30) Mar 1, '22 at 7:38 pm
Albert   I assume you meant VBA when you said "know nothing about MVB" you meant VBA. That being the case, you've effectively asked someone to do a project for you (against the Rules of the Forum BTW).  

Your attempt used an aporoach most appropriate for sheets which change fairly frequently but I imagine the Cover sheet might change once a year so I'm disinclined to do more (i.e. to correct the cell hyperlinks too and to hide where tabs the cells have no value) sorry.

I'd suggest you correct the typos in Cover (Mount instead of Mout) abd Balance (rather than Ballance) in other sheets.
John_Ru (rep: 6142) Mar 2, '22 at 10:37 am
Hi John.
VBA yes sorry.
The cover only changes based on other pages such as "Set" the cells show blank if the month hasn't arrived yet.
and I think I've corrected the typos, thanks for the advce, I didn't notice.
Sorry didn't realise it was against the rules. do I just delete this or what?
Thanks again John
wildecoyote1966 (rep: 30) Mar 9, '22 at 5:44 pm
No problem Albert, just leave this discussion as is (no need to delete). Sorry I don't have time to help on this one. 
John_Ru (rep: 6142) Mar 10, '22 at 1:24 am
Sorry John (not getting notifications)
I think I may have to pay someone
wildecoyote1966 (rep: 30) Mar 16, '22 at 7:03 am
Albert, perhaps you will. I don't think there's a lot to it (and I'm not doing any paid work) but I'm busy for a couple of days. There are sites where you can get offers to do a project but I don't know how good the results are (especially if you pick the cheapest, as in most things).

I did wonder if notifications were a bit sporadic - I got no response to several answers I provided recently (more than the normal ratio) but I am getting notifications where .a respnse occurs (like yours today).
John_Ru (rep: 6142) Mar 16, '22 at 8:32 am
Hi John

I never got a notification for your response only new questions. Sorry
Oh the tabs should only change once when you enter the details such as the state date then (only if hidden) when the new month arrives.
Any suggestions who to contact to get it fixed?
wildecoyote1966 (rep: 30) Mar 24, '22 at 10:24 pm
Albert.

Notifications are working for me- I've responded to an email saying you'd commented as above. Suggest you go to My Profile (near the top of the Forum page) and update Forum Settings to leave "Email updates when replies are made.."  to On - something like "turn it off, then turn it on again"!  Also check occasionally to see if you have comments.

Not sure what you mean by "state date" (didn't see it on your Cover sheet) but if the file tabs are updated monthly it sounds like fixing the macro would help you. Don't know who might fix the macro- pretty sure I could (but short of time at present) and I think it's too small for Don's consultancy work here.

Please explain the state date thing and I'll see it I can find time over the weekend to look at it..
John_Ru (rep: 6142) Mar 25, '22 at 3:42 am
Hi John
I did as you suggested thank you.

In reference to "State Date" I was refering to Tab "SET"  Cell C10 where you enter the "commencement date" from there the cells on the cells (months) on Cover appear.
wildecoyote1966 (rep: 30) Mar 25, '22 at 9:16 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login