Autofilter bug with Excel 2016/365 build 1706

It appears that there is a problem with Autofilters in the latest build (1706) where some values are not displayed in the filter dropdowns if you have a lot of data (say more than 20k rows). The only fix I am aware of currently is to revert back to the previous build, which didn’t have the same problem.

For instructions on reverting, see here.

Microsoft releases Script Lab – a tool for creating JS add-ins for Office

Posting an exciting announcement from Microsoft:

 

This morning we announced Script Lab, a crazy Microsoft Garage project for anyone who wants to learn about building add-ins!


Script Lab (formerly known as “Add-in Playground” and “Project Bornholm”) has three main features:

  • Code in a pane inside your Office file. IntelliSense shows suggestions while you type so you can easily discover and use the Office JavaScript objects and methods. And if you don’t want to start from scratch there are plenty of samples preinstalled with Script Lab. Your snippets can use any TypeScript features like the magical async/await and conveniences like arrow functions and template strings. But it’s not only script: your snippets can also use HTML, CSS, and references to external libraries and data on the web. Script Lab uses the Monaco editor, the same tech that powers VS Code, so it’s beautiful and lightweight.
  • Run the code in another pane beside the editor. Execution can include logic, API calls to Office, UI in the pane, and even output to a console. Every time you make a code change you can refresh the editor and run the new version in seconds.
  • Share your snippets through GitHub. If you create a snippet you’d like to share, you can use Script Lab to save it. Then send the link to someone else to try it and tweak it on their computer. The Import feature lets you load other people’s snippets. We think sharing will be especially useful for asking and answering questions about add-ins on Stack Overflow (http://stackoverflow.com/questions/tagged/office-js).

-The Script Lab team: Michael Z, Bhargav, Jakob, Daniel, and Michael S

Bug with VBA form controls transparency and Z-Order

There has been a bug introduced with the September update for Office 365 and Office 2016 perpetual which prevents controls on userforms from showing transparency or altering their Z-order properly.

 

Latest update from Microsoft is here. A fix is in the works and will hopefully be provided soon but, if you can’t wait, rolling back to an earlier build seems to be the best solution currently!

ByVal or ByRef – what’s the difference?

This is a question I see increasingly frequently in forums for some reason, so I thought I’d cobble together a brief synopsis.

ByRef passes a pointer to the variable, so any changes are reflected everywhere that variable is used.

ByVal passes a copy of a variable to a routine, so any changes to that variable will not be reflected in the original routine. In the case of objects, they are always passed as references (pointers) but if you pass an object ByVal you pass a copy of the pointer to the object rather than the original pointer (note: not a copy of the object)

Note: Array variables are always passed ByRef.

(This does not apply to Variants that happen to contain arrays, only to variables that are actually declared as an array.)

 

So here are some examples that will hopefully serve to illustrate the above:

  1. Using a simple data type:
Sub foo()

Dim i As Long
i = 1
Call Change_ByRef(i)
' i is changed by the Change_ByRef procedure and that change IS reflected here too because it was passed by reference
MsgBox "i is now: " & i
Call Change_ByVal(i)
' i is changed only within the Change_ByVal procedure because a COPY of it was passed
MsgBox "i is still: " & i

End Sub

Sub Change_ByRef(ByRef lInput As Long)
lInput = 14
End Sub

Sub Change_ByVal(ByVal lInput As Long)
lInput = 21
End Sub

2. Using an object variable, showing that when passed ByVal, you cannot change the orginal variable to make it point to a different object:

Sub Object_foo()

Dim r As Range
Set r = Range("A1")
Call Change_object_ByRef(r)
' r is changed to a different cell by the Change_ByRef procedure and
' that change IS reflected here too because it was passed by reference
MsgBox "r is now: " & r.Address
Call Change_object_ByVal(r)
' r is changed to a different cell by the Change_ByVal procedure but
' that change IS NOT reflected here because it was passed by value.
MsgBox "r is still: " & r.Address

End Sub

Sub Change_object_ByRef(ByRef rInput As Range)
' change the range variable to one row down
Set rInput = rInput.Offset(1)
End Sub

Sub Change_object_ByVal(ByVal rInput As Range)
' change the range variable to one row down
Set rInput = rInput.Offset(1)
End Sub

3. Again using an object variable, but this time showing that, even when passing ByVal, because you are still passing a pointer to the original object, you can change the properties of the object (you just can’t change which object the variable refers to):

Sub Object_foo2()

Dim r As Range
Set r = Range("A1")
Call Change_object_property_ByRef(r)
' r is given a different value by the Change_ByRef procedure and
' that change IS reflected here because an object reference is passed
MsgBox "r is now: " & r.Value
Call Change_object_property_ByVal(r)
' r is given a different value by the Change_ByVal procedure and
' that change IS reflected here because an object reference is still passed
MsgBox "r is now: " & r.Value

End Sub

Sub Change_object_property_ByRef(ByRef rInput As Range)
' change its value
rInput.Value = "changed byref"
End Sub

Sub Change_object_property_ByVal(ByVal rInput As Range)
' change its value
rInput.Value = "changed byval"
End Sub

For details of an exception to this rule, see the next post.

Transpose bug in 2013 and 2016

Many of us will be used to using Application.Transpose (or WorksheetFunction.Transpose) when manipulating ranges or arrays in VBA. And, up to and including Excel 2010, we are probably all aware that you will get a run-time error if you pass an array (not range) that is over 65536 ‘rows’.

 

The good news is that this error doesn’t occur in 2013 or 2016. The bad news is that the resulting array is not the size it should be and it gets truncated with no warning at all!

 

Essentially, what happens with an array that is over 65536 rows, the last whole multiple of 65536 rows are simply removed – i.e. you lose (n \ 65000) * 65000 rows.

So if your array is 65537 rows by 1 column, the resulting array will have 1 item. If it’s 85000 rows by 1 column, the result will have 19464 items (85000-65536*1). If you have 147000 rows, the result will have 15928  (being 147000-65536*2) and so on.

 

I’ve reported this but had no feedback as yet.

Super secret SpecialCells

I’m sure we’re all familiar with the Range.Specialcells method. If you’re not, you need to be, because it’s incredibly useful, so go and check it out now. Go on, we’ll wait.

 

OK, now that we’re all on the same page, you will be aware that there are 2 arguments you can supply to the SpecialCells method:

  • Type (required).
    • This is, naturally, the type of cells you are interested in and the available values are shown as those of the XlCellType Enum. More on this in a minute.

     

  • Value (Optional).

    When the Type argument is xlCellTypeConstants or xlCellTypeFormulas, you can specify which type(s) of values you are interested in:

Enum name

Literal value

xlNumbers

1

xlTextValues

2

xlLogical

4

xlErrors

16

 

Note: these values are additive (like the buttons for a MsgBox call), so if you want numbers and text, you can specify xlNumbers + xlTextValues

As far as I can tell, you can supply any number between 1 and 255 for the Value argument but it will be ignored if the Type argument is not xlCellTypeFormulas or xlCellTypeConstants, or if it’s not a valid combination of the values in the table above.

 

So, back to point 1 as promised. According to the documentation, the valid Type values are those of the XlCellType enumeration, namely:

 

Name

Literal value

xlCellTypeAllFormatConditions

-4172

xlCellTypeAllValidation

-4174

xlCellTypeBlanks

4

xlCellTypeComments

-4144

xlCellTypeConstants

2

xlCellTypeFormulas

-4123

rxlCellTypeLastCell

11

xlCellTypeSameFormatConditions

-4173

xlCellTypeSameValidation

-4175

xlCellTypeVisible

12

 

However, this is not in fact a complete list of the possible values you can pass. In addition, you can pass values which correspond (roughly) to the order in which the items appear in the Goto – Special… dialog (below)

 

 

Type number

Equivalent

Same as XlCellTypeEnum value

Range.SpecialCells(1)

Range.SpecialCells(xlCellTypeComments)

No

Range.SpecialCells(2)

Range.SpecialCells(xlCellTypeConstants)

Yes

Range.SpecialCells(3)

Range.SpecialCells(xlCellTypeFormulas)

No

Range.SpecialCells(4)

Range.SpecialCells(xlCellTypeBlanks)

Yes

Range.SpecialCells(5)

Range.CurrentRegion

No enum value

Range.SpecialCells(6)

Range.CurrentArray

No enum value

Range.SpecialCells(7)

Range.RowDifferences

No enum value

Range.SpecialCells(8)

Range.ColumnDifferences

No enum value

Range.SpecialCells(9)

Range.Precedents

No enum value

Range.SpecialCells(10)

Range.Dependents

No enum value

Range.SpecialCells(11)

Range.SpecialCells(xlCellTypeLastCell)

Yes

Range.SpecialCells(12)

Range.SpecialCells(xlCellTypeVisible)

Yes

Range.SpecialCells(13)

Range.SpecialCells(xlCellTypeAllFormatConditions)

No

Range.SpecialCells(14)

Range.SpecialCells(xlCellTypeAllValidation)

No

 

Hopefully this will prove useful to someone. J

 

A few key things to note:

If you use the SpecialCells method applied to one cell, it typically works as if applied to the entire worksheet. However, this is not true if you use 5, 6, 9 or 10 as the Type argument.

Prior to Excel 2010, specialcells can return a maximum of 8192 areas (discrete blocks of cells). If more areas than that apply, the returned range will be the whole of the original range.

I can at present find no way using 7, 8, 13 or 14 to provide the additional options available in the Goto – Special dialog since the Values parameter seems to simply be ignored.

TechDays Online – A Microsoft Azure special


 

Please help spread the word to as much of the technical community as possible about the Tech Days Online Microsoft Azure Special event; a three day digital event happening on the 2nd,3rd,4th of June and is part of the hugely popular Tech Days Online series. 

 

IT Professionals and Developers joining will get:

 

  • Community keynote sessions with respected industry figures showcasing what others are doing with Microsoft Azure – including Scott Hanselman, Acclaimed Developer, Microsoft
  • Over 15 deep technical sessions spanning Azure 101, Apps & Architecture, Data & Machine Learning and Cloud Infrastructure & DevOps delivered by Microsoft UK experts and Gold Learning Partner QA Training to help IT Pros and Devs get started TODAY
  • The opportunity to ask questions to all of our experts though live Q&A
  • A live mystery Microsoft Azure challenge and a competition to win a drone
  • Information on the offers available across MSDN/BizSpark etc and how to take a free trial of Microsoft Azure

 

Registration Link:

https://msdn.microsoft.com/en-gb/dn973263?ls=Inbound+Phone&lsd=MVP-Site&WT.mc_id=WBNR+MVP-comms+MAY15 

 

 

Feel free to use any of the following sample tweets and posts to encourage your followers & friends to register:

IT Pro

https://twitter.com/TechNetUK/status/598813781859258368

https://twitter.com/TechNetUK/status/598813725739483136 

https://twitter.com/TechNetUK/status/598813669808480256

 

Dev

https://twitter.com/msdevUK/status/598810060685316096

https://twitter.com/msdevUK/status/598810151081021441 

https://twitter.com/msdevUK/status/598810243494117376

 

Facebook ads here:

https://facebook.com/271725486227028/posts/892574690808768

https://facebook.com/271725486227028/posts/892575537475350

https://facebook.com/271725486227028/posts/892586637474240

https://facebook.com/613969575296338/posts/1132057673487523

https://facebook.com/613969575296338/posts/1132058216820802

https://facebook.com/613969575296338/posts/1132076460152311

Office 2016 public preview now available

For those of you who aren’t already aware, there is now a public preview of the forthcoming Office 2016 available for testing – see the official blog post here.

The official Preview site is here.

 

As usual, remember it’s not an official release yet, so it’s probably best not to use it on a production system! (though to be honest, I do at home, and haven’t had any issues)

 

Enjoy. IMO it’s worth downloading just to get the new colour schemes! 🙂