Skip to main content

One Range within Another


Excel has sophisticated methods available for users but it is easy to misunderstand what the program designer really meant. The Intersect method could be one of these.

I first used the method a little over 20 years ago. It allowed me to post a value in named column, in respect of specific transaction (formed by a row). At that time, the real advantage of this approach the location of the column could change without my having to rewrite the code. It would continue to be posted to the correct cell for the purposes of the overall program.

My current task – one range within another - sounds very similar. Indeed, when searching the web, the Intersect method was offered as a potential solution. However, there are some crucial / fundamental differences.

I was not looking for overlapping ranges. Rather, the whole of the smaller range had to be contained within the boundaries of the larger one. It became clear that I had examine each of the boundaries of the larger range individually and compare them with the equivalent boundaries of the smaller one. Only if all four comparisons were valid could I be sure that no part smaller range stepped outside the boundary of the larger one. This led to some rather tediously long-winded code shown below.
Image of VB code

Mistakes in code development – or are they?

The expectation of the code above is that the larger and smaller ranges will be on the same worksheet, but the requirement is not actually specified. So, I considered what the implications might be if the two ranges were on different worksheets.
  • The code relies exclusively on the numerical values of the boundary positions of the larger and smaller ranges. If those boundary positions were satisfied then the function would still deliver a TRUE result. At first, this seemed a perfectly worthless truism.
  • It then occurred to me that the code was written, assuming that the smaller range was indeed smaller. However, it was also written such that the individual boundaries could be the same. Taken to its logical conclusion, all four boundaries of the so called larger and smaller ranges could be the same.

Taking these two conclusions together, we have a methodology for proving that two ranges on different worksheets are of identical size and in identical locations.


Sheet1



Sheet2

This sounds more like a silly panel game from the BBC’s ‘I’m Sorry I haven’t aClue’, but, if anyone can identify a genuine use for the function, I'd be delighted.





Comments

Popular posts from this blog

Walberswick – June 2023

 Patrick and I chose the hottest week of the year so far to stay at Esme’s caravan in Walberswick. I spent the first few days on my own to check the workings of the caravan. It is old and showing signs of wear and tear, but the absence of curtains in large south facing window was a real irritation. Bryony saved the day by bringing our large picnic table cloth, which we were able to pin over the window for shade. That turned out to be vital given the weather. I claim that it was all the fault of COVID 19 that I am now over weight and unfit. I used these first few days to identify how unfit I was. The answer turned out to be “very”. The walking of the shingle beach from the camp site to the Blythe estuary was a nightmare. In previous years, I would get up early and walk for an hour or so before considering the activity for the day. This was based on a circular walk up the river path and over the heathland that surrounds Walberswick. Morning Walk This took rather longer than I had

What is a Cell Map?

It is a simplified, colour coded version of an Excel Worksheet. The map shows the structure of the worksheet, its input cells, constants, primary formula and 'named' ranges. The map is designed for spreadsheet developers who work in isolation (i.e. not part of a team), but who, nevertheless, build complex spreadsheet systems. It highlights oddities and inconsistencies within a spreadsheet structure. Excel has its own built-in auditing and mapping tools. Excel's name manager and formula auditing tools These are useful for auditing one formula or one name, but they become overburdened with detail when trying to audit/review a whole worksheet. The ACBA Mapping   [A revised version of the software is now available. Stephen Allen 05 September 2023] utility generates a map of the original spreadsheet and three map keys to aid the interpretation of the detail. For example, I went on strict weight reducing diet last year where I measured the weight/volume of everythin

ACBA Mapping: Employing ‘UsedRange’ in Excel

When reviewing a worksheet the ACBA Mapping software uses VBA’s ‘UsedRange’ function to identify the full scope of the sheet. This function is excellent for identifying separate ranges employed in a worksheet, but has some drawbacks. One of these drawbacks has been identified while reviewing the Enron corpus of files ( https://figshare.com/articles/dataset/Enron_Spreadsheets_and_Emails/1221767 ) The Enron corpus of spreadsheets and other correspondence is huge. Felienne Hermans however has whittled the number of workbooks down to 16,189 unique items.   https://www.felienne.com/archives/3634   The workbook that clearly displayed the UsedRange issue is named ‘benjamin_rogers__938__historical outages.xlsx’. Clearly the files have been renamed to prevent duplicates. In this blog though I will refer to it as ‘Historical Outages’. In the original Mapping software, users were advised when the ‘UsedRange’ exceeded half a million cells. This allows the user to escape from the process and t