Adding Control Box to Excel Worksheet

Post Reply
youngjedi
Posts: 19
Joined: Thu Apr 26, 2012 10:52 pm
OLAP Product: TM1
Version: 9.5 - 10.1
Excel Version: Microsoft Excel 2010

Adding Control Box to Excel Worksheet

Post by youngjedi »

I would like to add a vba driven control box with the available dimension elements to Excel. What is the code to do this??? The subnm function seems inefficient to me. I'd rather select from a drop down box and add a calculate line in the code so when I make the selection the form calculates immediately. If there is a better method I'm all ears.

Thanks
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Adding Control Box to Excel Worksheet

Post by tomok »

To each his own I suppose. I happen to like the SUBNM formula because using it provides a lot of flexibility and it can give your sheets a common look and feel to selecting dimension elements. If you would rather have your own drop-down the best way is to use Excel data validation on the cell. You can point your validation to a hidden tab in the workbook that contains a list of the dimension elements. In either case, just add code to the OnChange event of the cell where the dimension formula is to do a Worksheet.TM1RECALC1.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
Alan Kirk
Site Admin
Posts: 6667
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: Adding Control Box to Excel Worksheet

Post by Alan Kirk »

youngjedi wrote:I would like to add a vba driven control box with the available dimension elements to Excel. What is the code to do this??? The subnm function seems inefficient to me. I'd rather select from a drop down box and add a calculate line in the code so when I make the selection the form calculates immediately. If there is a better method I'm all ears.
I'm inclined to agree with Tomok. The other complicating factor is if the element is part of a dimension which has element security on it. At least the SubNm method presents only the elements that the user has access to. (If you think that SubNm is inefficient, try maintaining dynamic lists of elements that any given user has permissions for.)

However if you're prepared to try a little from column A and a little from column B and your main issue is that you want to recalculate upon selection, then rather than having a drop-down you also have the option of using a command button. The button could fire a VBA procedure which calls the E_PICK macro function. (Look under TM1 Macro Functions in the Reference Guide for details.) That will launch the subset editor so that the user can make a selection and you can punch the return value (if there is one) into the selection cell, then recalculate.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
youngjedi
Posts: 19
Joined: Thu Apr 26, 2012 10:52 pm
OLAP Product: TM1
Version: 9.5 - 10.1
Excel Version: Microsoft Excel 2010

Re: Adding Control Box to Excel Worksheet

Post by youngjedi »

Wow! Thanks for the quick feedback. If I decide to keep the subnm function in the sheet, how would I add that onchange event to a particular cell without tying it to an object in Excel?

Thanks again
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Adding Control Box to Excel Worksheet

Post by tomok »

youngjedi wrote:Wow! Thanks for the quick feedback. If I decide to keep the subnm function in the sheet, how would I add that onchange event to a particular cell without tying it to an object in Excel?

Thanks again
Go to Google and type in "tying onchange event to cell in vba". You will see a number of links that cover that very topic.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
nick_leeson
Posts: 98
Joined: Sat Feb 11, 2012 11:13 am
OLAP Product: TM1 9x, BPC, Hyperion, HANA
Version: TM1 10
Excel Version: Excel 2003 - 2010

Re: Adding Control Box to Excel Worksheet

Post by nick_leeson »

Personally I think your users would appreciate the vba driven control box better but then its horses for courses. Alan is spot on with the "recalculate upon selection'
I have used E_PICK and is great idea too.

p.s. Bear in mind the vba driven control box won't work at all on Websheets.
lotsaram
MVP
Posts: 3706
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Adding Control Box to Excel Worksheet

Post by lotsaram »

Bear in mind also that if you use the Worksheet_Change event and trigger TM1RECALC1 or TM1REFRESH on change of the dimension element reference in the target cell then in Excel 2010 this will crash Excel (fine in earlier versions of Excel.)

To avoid this you need something like the following:
If Val(Application.Version) < 14 Then
Application.Run "TM1RECALC1"
Else
Me.Calculate
End If
youngjedi
Posts: 19
Joined: Thu Apr 26, 2012 10:52 pm
OLAP Product: TM1
Version: 9.5 - 10.1
Excel Version: Microsoft Excel 2010

Re: Adding Control Box to Excel Worksheet

Post by youngjedi »

Here is the VBA code for anyone who wants to use it. I leveraged the fact that when the SUBMNM function clears, it puts the cursor in the immediate cell to the right, my SUBNM statement is actually in cell D2!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address(False, False) = "E2" Then Me.Calculate
End Sub
Post Reply