This is a macro I found online to freeze the first tab in my workbook. I am new to VBA, so please explain in details.
![]()
Please Login or Register to view this content.
This is a macro I found online to freeze the first tab in my workbook. I am new to VBA, so please explain in details.
![]()
Please Login or Register to view this content.
Last edited by arlu1201; 03-02-2013 at 07:10 AM.
Tome it does not look like it freezes anything. It just moves tabs around. Also you pass in sh but never use it. This looks like a poor coding attempt to me. Not even sure what it is attempting (what you mean by freeze).
Okay. The problem is I have about 30 different worksheet tabs. I want my very first tab in the workbook to not move or always stay visible as you scroll through all the tabs. Is there a macro that would accomplish this?Thanks for the help!
Hawkeye, it moves the selected Worksheet so it's the second tab along the bottom. Speaking of poor attempts, did you even try to read or test the code before you bashed it?
kdanilko, to make the code work you need to open the Visual Basic Editor, double click "ThisWorkbook" and put the code in there. You can then close VBE and when you select a worksheet you will notice the tab changes position.
That code is a bit messy though, you should use the following code instead:
Let me know if it works for you.![]()
Please Login or Register to view this content.
.
- AKK9 -
It takes sh as an input and never uses it. I stand by my poor coding comment. I pasted it and tried to replicate exactly what it was doing and it crashed my excel, and somehow anytime I opened that workbook it crashed excel immediately. Wasn't on a workbook open or anything so kind of weird - but yea. Bad code.
No, it's an event that occurs when a worksheet is activated. Sh is required, whether you use it or not is up to you.
Anyway, my point wasn't that the code was great (notice I replaced it with 1 line that does the same job). It's that it's pointless telling someone "bad code" after they've told you they're new to VBA, and they're posting to the forum specifically asking for help.
kdanilko,
Welcome to the forum.
I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
If I have helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
There seems to be some confusion on what role Sh plays here. Let me explain what this object variable is.
This is a Workbook level event. This event tracks the Worksheet level event SheetActivate. The object variable Sh (Sheet) is passed from the Worksheet event to the Workbook level event after the sheet is activated. Sh always points to the sheet that became the ActiveSheet in the workbook. Because it is a Worksheet object, you have access to all properties and methods of the original sheet.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
So leith, is it required (I am no expert but I have never seen a required input that is not even used like that). If I understand you could use sh.activate or similar statements. But is it required for an event like this? I guess I am less knowledgeable about the SheetActivate method than I thought.
Hello Hawkeye16,
The variable Sh is automatically provided to you by the event procedure. The user does not declare this variable nor is the user required to use it.
Thanks.
Maybe I explained it weird, to clarify, what I meant by 'required' is that the Sh parameter is required. As in, the event cannot fire without the Sh parameter being passed because it's required which is why I said "whether you use it or not is up to you".
Hello Everyone,
Thank you for all of your help.
AKK9, after pasting your code into VBE, I was unable to run the macro because it did not appear anywhere in the macro list. Again, I may be doing something wrong because I have no previous experience with VBE. Any suggestions?
Thanks again
you do not run it-it runs automatically when you switch between sheets.
Josie
if at first you don't succeed try doing it the way your wife told you to
kdanilko, once you have pasted your code it will run every time you select a sheet. Make some new sheets, and look at how the tabs reorganise whenever you select one.
Whenever you select a sheet, this code will move it so it's 2nd along the bottom. So you can access your first sheet easily, regardless of which tab you have selected.
Does it help?
Thanks AKK9!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks