Slow running code due to a lot of objects hiding / unhiding - performance

I have a spreadsheet of about 20,000 rows. This spreadsheet is a hierarchy that displays part lists for pieces of equipment. I have created code that creates buttons (actually the shape rectangle) that allow the user to expand / contract these groups through hiding / unhiding rows.
I believe the code is running slow because there are several thousand buttons on the spreadsheet that I believe are refreshing each time rows are hidden. When I click the button the code runs, the correct rows hide / unhide, then all the buttons dissapear for a few seconds then reapear. The disapearing occurs after the rows hide or unhide so the code has already finnished running.
Is there any way to stop Excel from refreshing every button? Is there a different issue?

It sounds like you could make use of the Pivot Table feature in Excel. I'm sure it's much faster than the macros/buttons the spreadsheet is using:
PIVOT TABLE OUTLINE
You just need to put in the effort of re-organizing your data into a decent format. Good Luck.
If you need an explanation of pivot tables you can just google "pivot table tutorial.
http://www.google.com/search?q=%22pivot+table+tutorial%22

I have used a workaround which I'll elaborate more when the code is handy,but is like so:
Have your button creating macro create hyperlinks in a cell instead with the text +/- and a tool tip of >>expand/collapse<<
ActiveSheet.Hyperlinks.Add _
Anchor:=[A1], Address:="", _
SubAddress:=[A1].Address, _
ScreenTip:=">>expand/collapse<<", _
TextToDisplay:="+/-"
In the workseet_followhyperlink event do a check to see if the tool tip is >>expand/collapse<< and if so follow you macro for sowing and hiding.
if target.screentip = ">>expand/collapse<<" then
myShowHideMacro
else
'do other stuff
end if

Related

How do you add UI inside cells in a google spreadsheet using app script?

I'd like to add buttons to specific cells in Google docs spreadsheet. The apps script UI documentation talks about how to add a new panel, but it's not clear how UI in that panel could be attached to specific rows or cells.
Is it possible to add UI to particular cells, or are we limited to adding new panels?
The apps UI only works for panels.
The best you can do is to draw a button yourself and put that into your spreadsheet. Than you can add a macro to it.
Go into "Insert > Drawing...", Draw a button and add it to the spreadsheet.
Than click it and click "assign Macro...", then insert the name of the function you wish to execute there. The function must be defined in a script in the spreadsheet.
Alternatively you can also draw the button somewhere else and insert it as an image.
More info: https://developers.google.com/apps-script/guides/menus
Status 2018:
There seems to be no way to place buttons (drawings, images) within cells in a way that would allow them to be linked to Apps Script functions.
This being said, there are some things that you can indeed do:
You can...
You can place images within cells using IMAGE(URL), but they cannot be linked to Apps Script functions.
You can place images within cells and link them to URLs using:
=HYPERLINK("http://example.com"; IMAGE("http://example.com/myimage.png"; 1))
You can create drawings as described in the answer of #Eduardo and they can be linked to Apps Script functions, but they will be stand-alone items that float freely "above" the spreadsheet and cannot be positioned in cells. They cannot be copied from cell to cell and they do not have a row or col position that the script function could read.
Use checkboxes(say, in F1) instead of buttons/Images. This is a intermediate to a full ui inside cells. Then hook your function, that is supposed to run on button click to onEdit() trigger function.
Sample script:
function onEdit(e){
const rg = e.range;
if(rg.getA1Notation() === "F1" && rg.isChecked() && rg.getSheet().getName() === "Sheet1"){
callFunctionAttachedToImage();
rg.uncheck();
}
}
References:
Class Range
Event Objects
Buttons can be added to frozen rows as images. Assigning a function within the attached script to the button makes it possible to run the function. The comment which says you can not is of course a very old comment, possibly things have changed now.
There is a silly trick to do something that might help you :
You can make the drawing object as tall as your sheet (To appear to every row in the sheet).
You can make the script affects the current cell value by the following code:
SpreadsheetApp.getActiveSpreadsheet().getActiveCell().setValue(cellValue);

Is there a way to nest an Excel spreadsheet within another Excel spreadsheet?

I am not entirely sure if this is the place to ask this, but this is the only think I could think of. I want to know if I could have a spreadsheet, say 10 cells wide. I would like the first 5 cells to be static, and the second 5 to be A/B based on, I guess a drop down? Not sure if this is possible, thanks for the input.
Both are possible.
In regards to the static question, you want to look at Excel's ability to Split the worksheet and then Freeze sections. With Excel 2007 you can find this within the View ribbon and Window group. (I am not sure of the exact menu terminology.)
For a cell to act as a Dropdown, you want to look at Data Validation. This option (with Excel 2007) is found under the Data ribbon within the Data Tools section. This allows you to set a given cell to dates, times, whole numbers, and lists. With the list you set the source to a range elsewhere in the workbook and the cell will render as a dropdown.
Hope this helps.

What are ways to reduce the number of columns in a table/grid?

I have a datagrid with many columns. This makes it pretty wide. Now we want to add more information to the table. Aside from removing or shortening existing columns what are some ways we might be able to add additional information without adding new columnes.
The data we want to add would be one of several values. For example:
Projected
Actual
Other
For other cases when the value was an off/on or true/false we would change the color of the row. In this case that doesn't seem to be a good option.
Another thing we considered is using an icon to indicate the information.
Any other ways this could be done?
A solution i've seen implemented with grid components is to have a column chooser - some sort of popup dialog that lists the columns and you can select which ones you would like to see in the grid. You should be able to invoke this popup by triggering it from the grid, e.g. it might appear as an option when the user right clicks and causes the context menu to appear.
Can you group related information into tabs?
an overflow area? ie a number of fields underneath the table that populate based on the selected row.
or just only show the minimum needed info and the have full details in a popup when doble clicked or something..
1) Popup on row hover
2) Drop open inline in the grid with extra info on row click
One technique I've used in the past was to create a "container" type of class that has its own labels and textboxes, and you can arrange them however you want, then insert this class into a single grid column. You still have to do some tricks on binding multiple controls that are not native "grid column" controls, but should help you along. Then, you can actually have each row a single container control in a single grid column...
You can't add completely new data to a grid without reserving a column to display it. The best solution I've seen is to provide only the essential information in the grid displaying all records, and then create a drilldown view that shows all of the data for one row. The drilldown can either be a new view in the same form, a popup for an additional window, or perhaps a mouseover popup.
I've worked on systems that use all sorts of shortcuts to display every last bit of information on a single page, and I found that it just made everything more confusing and harder to use. "Oh, that little icon there means that <insert something totally unrelated to the icon picture>."

mouse pointer and thumb nail for selection

What would be the appropriate way for selecting a particular row in a paginated view.
For example, while trying to select a particular row in Yahoo Inbox you can use the pointer to select the check box and if you try to click beyond the check box, no action is taken.
But while trying to select a particular row in GMail Inbox you can use the pointer to select it or if you navigate away from the checkbox it changes into a thumbnail but allows you to select the row.
Which method is preferable from a usability perspective and how to implement the thumbnail based selection as done by GMail
Both methods are appropriate, and both can be very usable.
I think the main difference is that row selection (the system used by Gmail) is more like a desktop application and a little less web-like. With links (like in the Yahoo inbox or StackOverflow), it's completely obvious that you're supposed to click on them. With rows, you sort of have to figure that out that you can click them, but I doubt it takes people long.
One thing to keep in mind is that, if you go with row selection, it's probably a good idea to bunch together any other clickable control (like checkboxes, links, or "favorite" stars). This way, you can click anywhere on the row. If you intersperse controls along the row, you increase the likelihood users will make clicking errors (aiming for the row but accidentally clicking some other control), and it will make it harder for users to recognize that the row itself is a clickable region.
So, both are perfectly acceptable user interfaces. You'll have to decide which one is a better match for your particular situation. I think, in general, links are a little bit more versatile, but with clickable rows, you know you can click anywhere and it will work.

Disable column in MSHFlexGrid in VB6.0

How do I disable particular columns in MSHFlexgrid in VB6.0? I don't want my user to edit the values in a particular column.
I don't think the MSHFlexGrid control allows users to edit its data in the first place. Therefore, in effect, all columns are disabled. Job done :)
In fact, you have to add custom code to enable updating e.g. add an appropriate control (textbox, combo, date picker, etc) that does allow editing, hide it at design time, then at run time detect which grid cell should have focus, move and size the control to fit the cell then make it visible then handle events to validate the input then write the contents back to the recordset...
...or you could purchase a third party control that does all this out of the box. The MSHFlexGrid that ships with VB6 is essentially a cut-down version of VSFlexGrid Pro, which I've used and thought was quite good. It has a different way of handling hierarchical data by creating groups (rather than bands) which is superior, IMO. The best thing that can be said about the MSHFlexGrid is that it is easy to bind to a hierarchical ADO recordset to simply display the results but not good if you want to do nice formatting or make the grid editable. The VSFlexGrid Pro, if you can afford it, has more power e.g. you can create data source classes to handle binding to custom data structures (ships with VB6 examples of this including ADO recordset binding) which would be invaluable IMO if you intend to make your hierarchical grid editable.
'A Shortcut way is here... NOT in a proper way. But you can try
'if you need to lock the first 3 columns please use this code:
msf2=name of MSFlexGrid
Private Sub msF2_EnterCell()
With msF2
If msF2.Col = 0 Or msF2.Col = 1 Or msF2.Col = 2 Then
msF2.Col = 3
End If
End With
End Sub

Resources