buttons go in hiding when I run macro

%3CLINGO-SUB%20id%3D%22lingo-sub-1445954%22%20slang%3D%22en-US%22%3Ebuttons%20go%20in%20hiding%20when%20I%20run%20macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1445954%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%20everyone%20I'm%20really%20new%20to%20macros%20and%20vba%20but%20going%20through%20net%20I%20studied%20and%20found%20this%20article%20to%20make%20attendance%20of%20employee%20for%20which%20I%20made%20accordingly.%20the%20buttons%20are%20all%20months%20like%20apr%2C%20may%2C%20June%20....%20I%20have%20made%20the%20same%20thing%20thrice%20and%20every%20time%20I%20assign%20in%20properties%20of%20buttons%20to%20not%20move%20or%20merge%20and%20so%20on%20but%20still%20when%20I%20run%20macro%20all%20buttons%20get%20merged%20into%201%20and%20I%20cannot%20see%20other%20months.%20also%20if%20I%20want%20to%20redo%20macro%20and%20press%20stop%2Fbreak%20I%20cannot%20see%20the%20full%20sheet%20It%20is%20for%20this%20reason%20I%20have%20made%20so%20many%20sheets%20as%20I%20go%20on%20copying%20else%20it%20will%20take%20me%20workload%20to%20do%20it%3C%2FP%3E%3CP%3Eplease%20advice%20me%20for%20eg%20in%20sheet4%20(3)%20why%20the%20button%20combines%20into%201%20and%20if%20I%20want%20to%20stop%20macro%20to%20run%20so%20that%20I%20can%20see%20the%20full%20worksheet%20what%20should%20I%20do.%3C%2FP%3E%3CP%3Eplease%20help%3C%2FP%3E%3CP%3Ethanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1445954%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1446052%22%20slang%3D%22en-US%22%3ERe%3A%20buttons%20go%20in%20hiding%20when%20I%20run%20macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1446052%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F691317%22%20target%3D%22_blank%22%3E%40ieesh1712%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20set%20the%20property%20of%20each%20shape%20as%20%22Don't%20move%20or%20size%20with%20cells%22%2C%20when%20you%20hide%20the%20columns%2C%20there%20is%20no%20place%20left%20for%20the%20buttons%20since%20the%20columns%20they%20were%20sitting%20in%20got%20hidden%20so%20they%20gets%20screwed%20up%20and%20sit%20on%20each%20other.%3C%2FP%3E%3CP%3EYou%20could%20set%20the%20property%20as%20Move%20and%20size%20with%20cells%20so%20that%20they%20remain%20intact%20with%20the%20source%20columns.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInstead%20of%20populating%20the%20attendance%20for%20each%20month%20across%20the%20columns%2C%20you%20may%20populated%20them%20across%20the%20rows%20as%20shown%20in%20the%20Attendance(2)%20Sheet%20(green%20tab).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20created%20some%20named%20ranges%20for%20each%20month%20and%20set%20the%20same%20captions%20for%20all%20the%20months%20buttons%20and%20then%20assigned%20the%20following%20macro%20to%20all%20the%20month%20buttons%20as%20you%20need%20only%20one%20macro%20which%20would%20work%20for%20all%20the%20buttons.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20macro%20which%20should%20assigned%20to%20all%20the%20buttons%20is%20as%20below...%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20NavigateToMonthlyAttendance()%0ADim%20shp%20%20%20%20%20As%20Shape%0ADim%20rng%20%20%20%20%20As%20Range%0ADim%20strRng%20%20As%20String%0A%0ASet%20shp%20%3D%20ActiveSheet.Shapes(Application.Caller)%0AstrRng%20%3D%20shp.TextFrame2.TextRange.Text%0ASet%20rng%20%3D%20Range(strRng)%0A%0AApplication.Goto%20rng%2C%20True%0Arng.Cells(3%2C%203).Select%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20more%20details%2C%20please%20refer%20to%20the%20Sheet%20Attendance(2)%20in%20the%20attached.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1452903%22%20slang%3D%22en-US%22%3ERe%3A%20buttons%20go%20in%20hiding%20when%20I%20run%20macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1452903%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3Bthanks%20a%20million%20solved%20the%20purpose%20and%20will%20just%20try%20to%20understand%20it%3C%2FP%3E%3CP%3E1%20more%20thing%20if%20I%20want%20to%20view%20the%20full%20sheet%20without%20running%20vba%20how%20do%20I%20do%20that%20because%20even%20if%20I%20press%20stop(break)%20it%20only%20shows%20what%20I%20had%20pressed%20last%20time%20the%20button%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1453334%22%20slang%3D%22en-US%22%3ERe%3A%20buttons%20go%20in%20hiding%20when%20I%20run%20macro%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1453334%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F691317%22%20target%3D%22_blank%22%3E%40ieesh1712%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20are%20talking%20about%20the%20layout%20in%20Attendance(2)%20sheet%2C%20all%20you%20need%20is%20to%20click%20the%20Apr%20button%20and%20the%20top%20month%20April%20will%20be%20displayed%20on%20the%20top.%3C%2FP%3E%3CP%3EIn%20this%20approach%2C%20no%20rows%20or%20columns%20are%20being%20hidden%20but%20the%20desired%20month%20range%20comes%20on%20the%20top%2C%20that's%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20far%20as%20your%20original%20approach%20is%20concerned%20you%20may%20insert%20a%20button%20with%20the%20following%20code%20underneath%20it%20to%20unhide%20all%20the%20columns...%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3ESub%20UnHideColumns()%0AActiveSheet.UsedRange.Columns.Hidden%20%3D%20False%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20that%20takes%20care%20of%20your%20original%20question%2C%20please%20take%20a%20minute%20to%20accept%20the%20post%20with%20the%20solution%20provided%20as%20a%20%3CSTRONG%3EBest%20Response%3C%2FSTRONG%3E%20to%20mark%20your%20question%20as%20Solved.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

hi everyone I'm really new to macros and vba but going through net I studied and found this article to make attendance of employee for which I made accordingly. the buttons are all months like apr, may, June .... I have made the same thing thrice and every time I assign in properties of buttons to not move or merge and so on but still when I run macro all buttons get merged into 1 and I cannot see other months. also if I want to redo macro and press stop/break I cannot see the full sheet It is for this reason I have made so many sheets as I go on copying else it will take me workload to do it

please advice me for eg in sheet4 (3) why the button combines into 1 and if I want to stop macro to run so that I can see the full worksheet what should I do.

please help

thanks

3 Replies
Highlighted

@ieesh1712 

 

If you set the property of each shape as "Don't move or size with cells", when you hide the columns, there is no place left for the buttons since the columns they were sitting in got hidden so they gets screwed up and sit on each other.

You could set the property as Move and size with cells so that they remain intact with the source columns.

 

Instead of populating the attendance for each month across the columns, you may populated them across the rows as shown in the Attendance(2) Sheet (green tab).

 

I have created some named ranges for each month and set the same captions for all the months buttons and then assigned the following macro to all the month buttons as you need only one macro which would work for all the buttons.

 

The macro which should assigned to all the buttons is as below...

Sub NavigateToMonthlyAttendance()
Dim shp     As Shape
Dim rng     As Range
Dim strRng  As String

Set shp = ActiveSheet.Shapes(Application.Caller)
strRng = shp.TextFrame2.TextRange.Text
Set rng = Range(strRng)

Application.Goto rng, True
rng.Cells(3, 3).Select
End Sub

 

For more details, please refer to the Sheet Attendance(2) in the attached.

 

 

 

 

Highlighted

@Subodh_Tiwari_sktneer thanks a million solved the purpose and will just try to understand it

1 more thing if I want to view the full sheet without running vba how do I do that because even if I press stop(break) it only shows what I had pressed last time the button

Highlighted

@ieesh1712 

 

If you are talking about the layout in Attendance(2) sheet, all you need is to click the Apr button and the top month April will be displayed on the top.

In this approach, no rows or columns are being hidden but the desired month range comes on the top, that's it.

 

As far as your original approach is concerned you may insert a button with the following code underneath it to unhide all the columns...

Sub UnHideColumns()
ActiveSheet.UsedRange.Columns.Hidden = False
End Sub

 

If that takes care of your original question, please take a minute to accept the post with the solution provided as a Best Response to mark your question as Solved.