Something that I came across while searching for something else… And this is such vital information, that you hardly ever stumble upon this when required!

Worksheet and workbook specifications and limits

Feature

Maximum limit

Open workbooks Limited by available memory and system resources
Worksheet size 1,048,576 rows by 16,384 columns
Column width 255 characters
Row height 409 points
Page breaks 1,026 horizontal and vertical
Total number of characters that a cell can contain 32,767 characters
Characters in a header or footer 255
Sheets in a workbook Limited by available memory (default is 3 sheets)
Colors in a workbook 16 million colors (32 bit with full access to 24 bit color spectrum)
Named views in a workbook Limited by available memory
Unique cell formats/cell styles 64,000
Fill styles 256
Line weight and styles 256
Unique font types 1,024 global fonts available for use; 512 per workbook
Number formats in a workbook Between 200 and 250, depending on the language version of Excel that you have installed
Names in a workbook Limited by available memory
Windows in a workbook Limited by available memory
Panes in a window 4
Linked sheets Limited by available memory
Scenarios Limited by available memory; a summary report shows only the first 251 scenarios
Changing cells in a scenario 32
Adjustable cells in Solver 200
Custom functions Limited by available memory
Zoom range 10 percent to 400 percent
Reports Limited by available memory
Sort references 64 in a single sort; unlimited when using sequential sorts
Undo levels 100
Fields in a data form 32
Workbook parameters 255 parameters per workbook
Filter drop-down lists 10,000

 

Calculation specifications and limits

Feature

Maximum limit

Number precision 15 digits
Smallest allowed negative number -2.2251E-308
Smallest allowed positive number 2.2251E-308
Largest allowed positive number 9.99999999999999E+307
Largest allowed negative number -9.99999999999999E+307
Largest allowed positive number via formula 1.7976931348623158e+308
Largest allowed negative number via formula -1.7976931348623158e+308
Length of formula contents 8,192 characters
Internal length of formula 16,384 bytes
Iterations 32,767
Worksheet arrays Limited by available memory
Selected ranges 2,048
Arguments in a function 255
Nested levels of functions 64
User defined function categories 255
Number of available worksheet functions 341
Size of the operand stack 1,024
Cross-worksheet dependency 64,000 worksheets that can refer to other sheets
Cross-worksheet array formula dependency Limited by available memory
Area dependency Limited by available memory
Area dependency per worksheet Limited by available memory
Dependency on a single cell 4 billion formulas that can depend on a single cell
Linked cell content length from closed workbooks 32,767
Earliest date allowed for calculation January 1, 1900 (January 1, 1904, if 1904 date system is used)
Latest date allowed for calculation December 31, 9999
Largest amount of time that can be entered 9999:59:59

 

Charting specifications and limits

Feature

Maximum limit

Charts linked to a worksheet Limited by available memory
Worksheets referred to by a chart 255
Data series in one chart 255
Data points in a data series for 2-D charts 32,000
Data points in a data series for 3-D charts 4,000
Data points for all data series in one chart 256,000

 

PivotTable and PivotChart report specifications and limits

Feature

Maximum limit

PivotTable reports on a sheet Limited by available memory
Unique items per field 1,048,576
Row or column fields in a PivotTable report Limited by available memory
Report filters in a PivotTable report 256 (may be limited by available memory)
Value fields in a PivotTable report 256
Calculated item formulas in a PivotTable report Limited by available memory
Report filters in a PivotChart report 256 (may be limited by available memory)
Value fields in a PivotChart report 256
Calculated item formulas in a PivotChart report Limited by available memory
Length of the MDX name for a PivotTable item 32,767
Length for a relational PivotTable string 32,767

 

Shared workbook specifications and limits

Feature

Maximum limit

Users who can open and share a shared workbook at the same time 256
Personal views in a shared workbook Limited by available memory
Days that change history is maintained 32,767 (default is 30 days)
Workbooks that can be merged at one time Limited by available memory
Cells that can be highlighted in a shared workbook 32,767
Colors used to identify changes made by different users when change highlighting is turned on 32 (each user is identified by a separate color; changes made by the current user are highlighted with navy blue)
Excel tables in a shared workbook 0 (zero)

 Note   A workbook that contains one or more Excel tables cannot be shared.

 

References -

I’ve talked about Array Formulas at a very nascent level in some of my earlier posts, nothing particularly in detail though! There are many sites for that, and that’s what you can find in my older post Array Formula in Excel – A Quickie.

Then what is this post all about?! Well, Array Formulae are generally used while working with Excel Worksheets – very handy when quick matrix math is required. But if I wanted to automate this using VBA, how do I do it?

Range(“”).FormulaArray = <formula>

And we’re done!!!

All’s well till your <formula> exceeds 256 characters!

‘.FormulaArray’ only supports when the character length is under 256, an error throws up otherwise. Surprisingly, this is not the case with ‘.Formula’ – no such limit on this.

How do you know when this happens? You get a run-time error 1004, stating inability to accept Range. Check out Microsoft’s link to know more.

So, what’s the workaround? Or is there one?! Ofcourse! There always is one!

1. A potentially notorious workaround I should say – using the ‘Sendkeys’ from VBA to send a ‘F2+Shift+Ctrl+Enter’ after entering the ‘.FormulaArray’ as a ‘.Formula’!

Range(“”).Select

SendKeys “{F2}^+{ENTER}”, Wait:=True

Application.Wait (Now() + TimeValue(“00:00:01″)) ‘(Usually required since VBA doesn’t necessarily wait for the execution of the ‘SendKeys’ statement!)

Although slightly twisted, I liked this approach since it solves the problem quite easily. BUT, beware, this could create bugs in the code execution or final results in ways you can’t even think of! And this is primarily due to the disconnect between VBA & Excel interface!

2. This is probably a very well thought out solution and easier in terms of operational complexity but requires more work in terms of code. It’s best read directly at Dick Kusleika’s blog – http://www.dailydoseofexcel.com/archives/2004/04/05/anatomy-of-an-array-formula/.

What this does is simply break the <formula> into multiple strings and submit the first ‘.FormulaArray‘ with the first segment with fillers that will be substituted the remaining bits of the broken formula! Ingenious!

And now you’re all set to be automating Array Formulas from VBA…

Despite unlimited online help and material, I find people are always confused when it comes to INDEX. Actually, for that matter, any function in Excel I should say, till they get very comfortable.

The problem occurs particularly when multiple nested functions are involved, making it quite cumbersome and tedious to debug/explore. Although, with what could be a very meticulous approach of indenting and use of line returns to mark end of each separate level of formula we could make the whole process easier, a stronger understanding of the process or function in this case, could help you a longer way! And that’s what I intend to do with the ‘Back to the Basics’ series…

Let’s take up the INDEX function as this is one of the ‘most sought after formula’ in Excel, yet quite a pain if you did not know how this worked. Let’s quickly take an example from below -

= INDEX (Data!A1:AX1000, MATCH(IF(XFB1,INDIRECT(A2&”_Year”),INDIRECT(B2&”_Year”)), Data_Row,0),MATCH(C1,Data_Col,0))

A formula like above, and the newer folks are quickly put off – even before they started to try! Once you get to know what this is all about, you’ll jump at the opportunity to look at a function like this! Trust me…

For starters, I prefer to visualize my excel operations in a very pictorial way and that’s MY way of doing it – but the essence still remains, you have to visualize the ‘BASICS’! So, let’s get started then…

First off, INDEX function is used to pick a value from a table/matrix/2D array – call it anyway you please. The syntax goes like this -

= INDEX ( Table Range, Row Number, Column Number)

Let’s take an example….

And if I wanted to pick the numbers in the columns C & D one by one, how would I do it? I would like to use the INDEX function for this very purpose, in this way -

= INDEX(A2:D7, 2, 3)                 –>  would give B’s Orders total of 345

= INDEX(A2:D7, 4, 4)                 –>  would give D’s Sales total of 20.6

Or this could be done another way…

= INDEX(C2:C7, 2, 1)                 –>  would give B’s Orders total of 345

= INDEX(D2:D7, 4, 1)                 –>  would give D’s Sales total of 20.6

Either way, we get what we wanted, the Columns C & D referenced.

In both the cases above, what mattered most is – the relative referencing of the Row & Column No. to the Table that has been defined.

Now, if it’s so simple, why all the complications in the formula? Well, in the formulae above, the Row & Column No. has been hard coded – i.e. it’s is fixed and doesn’t change. What if we needed something more automated, something more dynamic? That’s when we use different methods to arrive at the Row & Column No. – INDIRECT, MATCH etc.. Take a

look below..

If we wanted to reference the data of any of the above queries (Yes, that’s the technical term for fetching some data given some criteria), the formulae to the right is how we would do it – but would that help? If I changed any of the criteria, the formula wouldn’t hold good any longer! Why? Since the row & column no.s are hard coded! So, if I wanted to check for orders for A, I’ll have to manually edit the formula to =INDEX(A2:D7,2,3).

This is where dynamic referencing makes all the difference! Take a look below -

Agreed this look more complicated, but this does all the work you want! All it does is, in the places where we had the Row & Column No.s, we plug in a formula that will get us that by looking up our criteria! Brilliant, ain’t it?!

So, above, even if I were to change my criteria to anything else, like A’s Orders or E’s Sales etc, the formula would automatically reference the correct data!

And that’s all there is to the INDEX formula!!!

Do me this favour – Next time, you encounter the INDEX, break it down into the following 3 components:

  1. The Table Array
  2. The Row No. of the ITEM
  3. The Column No. of the ITEM

And then, go about debugging/creating your dynamic references! And you’ll be home in no time!!!

So, taking a look at what we had started with -

= INDEX (Data!A1:AX1000, MATCH(IF(XFB1,INDIRECT(A2&”_Year”),INDIRECT(B2&”_Year”)), Data_Row,0),

MATCH(C1,Data_Col,0))

  1. The Table Array –> Data!A1:AX1000
  2. The Row No. of the ITEM –> MATCH(IF(XFB1,INDIRECT(A2&”_Year”),INDIRECT(B2&”_Year”)), Data_Row,0)
  3. The Column No. of the ITEM –> MATCH(C1,Data_Col,0)

So, go ahead and crack down every little piece of formula you have now!

Here’s the scenario – you’re programming using VBA, but interacting with Excel sheet formulae/other aspects of Excel (like Charts or Pivots), and when the scale becomes large, you see errors in your sheet updation – like data is not represented correctly or charts are not updated uniformly etc.

And this is not as a result of bugs in your programming logic or algorithm, but merely a bug in ‘time’!

Time?? Yes, the time involved for Excel to update while VBA doesn’t wait that long enough to process and hence a ‘time sync error’! This is a common error in many areas of science; occurs when two different engines are working together to produce a result – it could be mechanics, electronics or computers.

And the way this ‘has’ to work is – both the engines be sync-ed to a common speed – necessarily the slower one between the two. It’s like this – In the scenario of computer hardware, the Processor is a very fast engine but the Memory is not as fast. If the Processor were to process information even before the Memory could dispatch, what would result is processing of wrong data!

This is the same that happens with Excel & VBA, and when you’re in the VBA mode, you have  to wait for Excel to finish its calculations and screen updations and the like (unless you’ve turned them off manually on VBA).

So, how do we do this? Simple, just ask VBA to WAIT! Yes, it’s that simple!

The way to do this would be to include a

Application.WAIT (Now() + TimeValue(“00:00:01″))

What the above line does is, ask the VBA processor to wait for a second before moving on with the processing! That simple!

But isn’t 1 sec too long a time  to wait?! MAYBE!

In which case, there are some other functions out there that can help you, but not WAIT. WAIT is defined to delay the process only in multiples of seconds – so, the smallest unit you can use is 1 sec! Sometimes, you don’t need to wait that long, you may only need a few milliseconds – then what?!

You’ve got another function called SLEEP then. It’s a Microsoft API routine, and hence slightly different inherently, but yes, you are calling for help from outside of VBA’s territory now! There are pros and cons for using this, but let’s keep this for later! For now, it’s just WAIT and learn…


Very recent discovery for me, and hence very fresh too! It’s common knowledge that files outside of Excel can be accessed from VBA, but I never quite got to laying my hands on that information deep enough. Time and Opportunity has presented me with that now.

“File Access” when I say, it’s about reading, writing or appending data to files – any type of files, but what I’m here to talk about is a specific set of them : text files, binary files, log files, .ini files and the like. So, I’m not concerned with opening other types like .xls or .doc! Why not? No special reason, just that I’ve not read much about them yet! ! If I give it a try sometime, I’ll post!

Why do we need such a facility as File Access? It’s fast, it happens back end, and helps optimize memory usage! But more importantly, it’s FULL MANUAL control of how and where the files are written and stored, thus not only is it about efficiency, it is also about propriety!

Propriety?! Yes, Indeed! The files are nothing but many records grouped together. And how I define a record, and more specifically, each field in the record, the no. of fields,  the location of each of them etc makes it a propriety, in that, without knowing those attribs, it makes it difficult to make sense from the stored data in the files!

Types of File Acces from VBA – Essentially, there are three ways to do this:

  1. Binary Access
  2. Random Access
  3. Sequential Access
  4. Microsoft Scripting Runtime (yet to get familiar)

I would rather redirect you to the right sources than redefine each here and explain. But to quickly summarize what is used where, and why, read on…

Random Access is used to write fixed length fields/records and hence very quick and easy to code. For instance, using a 2-byte data type for all fields in the records. The drawback – since data could be of variable size, having a fixed size could lead to wastage of memory. Here’s where we switch to Binary Access, where we can define custom length for each record/field! The cons – it takes more effort from the programmer to do this! A third type of access, the Sequential Access, is more of a quick to use tool, like creating lines of Log. It uses up a lot of memory space but is useful in terms of quick writes.

Since I’m getting used to these as well, I can’t delve into too much detail readily, but will do in subsequent posts. In the meantime, I could give away some nice read material on this and maybe we could have a discussion around this again sometime….

References:

  1. http://www.erlandsendata.no/english/index.php?t=envbafileaccess – An amazing site with a quick summary; additionally, the site caters to more stuff, could keep you occupied for longer!
  2. http://www.developerfusion.com/article/85/binary-files/(Must Read) Well written article on what exactly is a Binary file! The comments make it a BIG source of thoughts.
  3. http://support.microsoft.com/kb/257794 – Microsoft Help, very helpful! Mainly around Binary Access.
  4. http://support.microsoft.com/kb/151335 – Ditto
  5. http://www.powerbasic.com/support/help/pbcc/index.htm#put_statement.htm – Online Syntax Dictionary for VB; necessary to get to know routines like PUT or GET etc.
  6. Finally, this is a book that I ended up discovering, one that I’ve never come across – and this is on VB & VBA. If you can get a copy of this, take a dig – VB & VBA in a Nutshell: The Language – Paul Lomax.pdf

Next Page »

Follow

Get every new post delivered to your Inbox.

Join 32 other followers