Hello. I see that there are various posts related to my query, but I'm a novice when it comes to macros, and I'm not able to effectively use the code posted for someone else and modify it to my purposes, so I must apologize if my problem seems redundant.
I'm trying to make a simple macro that will hide a sheet if the value in C1 is "True" based on a logic function that exams whether the date in C3 is equal to today's date. I would like this run when the sheet is opened if possible. I have the below code, but it doesn't seem to be working.
Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In Worksheets
If Not ws.Range(C1) = "True" Then ws.Visible = False
Next ws
End Sub
Any help would be greatly appreciated. Thanks!
hi try use such code
p.s. the "True" in code is not equal to True as the result of logical function from cell so I put the logical equitation into codePrivate Sub Workbook_Open() Dim ws As Worksheet For Each ws In Worksheets If ws.Range("C1") <> "" Then If ws.Range("C1") = ws.Range("C3") Then ws.Visible = False End If End If Next ws End Sub
Regards
tom1977
If You are satisfied with my solution click the small star icon on the left to say thanks.
cancelled post
Regards
tom1977
If You are satisfied with my solution click the small star icon on the left to say thanks.
look at attachment and tell me is it ok? if not put your description on my file. And remember that you can’t hide all sheets or workbook.
Regards
tom1977
If You are satisfied with my solution click the small star icon on the left to say thanks.
I opened the file, and I'm seeing 3 tabs. Essentially, what I'm trying to accomplish is to have only one tab visible at a time, and that tab would be "today's" tab. I'm attaching my file because I don't think I've done a very good job of explaining. Again, thanks so much!
Hi
First You choosed wrong place to insert the code: You should put this into Thisworkbook module
Second I changed code to this:
with this You do not need any value in C1Private Sub Workbook_Open() Dim ws As Worksheet For Each ws In Worksheets If ws.Range("C2") = Date Then ws.Visible = False End If Next ws End Sub
Regards
tom1977
If You are satisfied with my solution click the small star icon on the left to say thanks.
I think this is close, but instead of only showing today's tab, it's only hiding today's tab. Thanks!
so change this
If ws.Range("C2") = Date
into this
If ws.Range("C2") <> Date
Regards
tom1977
If You are satisfied with my solution click the small star icon on the left to say thanks.
It worked! Thank you so much! I know that this was probably frustrating for you, but I really appreciate all of your help and patience!
Do not worry I am not frustratedgood luck with VBA
Regards
tom1977
If You are satisfied with my solution click the small star icon on the left to say thanks.
Hi again,
I'm sorry to bother you, but when I opened the file this morning to make sure that yesterday's sheet would hide, and today's would open, it got a run time error of 1004. When I go in to VBA, it appears that the problem is in the "ws.visible=false" line, as it is highlighted in yellow. Do you have any thoughts on what would be causing that error?
Thanks so much!
Are you sure at my computer is ok
which line is indicated as error?
Regards
tom1977
If You are satisfied with my solution click the small star icon on the left to say thanks.
It's working fine now. Sorry! But I do have another question. It came up today that people would like to see all the tabs for the coming week, so it would be a rolling 7 days worth of tabs showing. Is that possible to accomplish that by adjusting the code you've already given me? Again, thank you so much!
Hi again Tom1977,
I'm getting the debut error when I try to open the file and have the macro run instantly. It's saying that the "ws.visible=False" line isn't working right. Any thoughts?
Thanks!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks