Agree row and column is not a worksheet concept. But it is as you say a function of the way arrays are stored in memory. And they might as well make it match the way excel is used. It also defines the most efficient way to nest loops in multidimension arrays. Redim preserve does not say you can only expand columns, it says you can only expand the last dimension so if you have a 5 dimension array you can only expand dimension 5. The rightmost dimension changes fastest so in memory for a 2 dimension array you have all of row 1's columns then all of row 2's columns etc which means in a loop you want the column loop to be the inner loop. True of every language though some reverse the precedence order. I think they should have made redim preserve have the first dimension be the one that can change. But then since they create a new copy anyway I see no reason all dimensions can not change. It really makes no sense to say you can increase all dimension if tossing the contents but not if keeping them. Somebody took an implementation shortcut.
On Wed, Apr 11, 2012 at 8:32 PM, Asa Rossoff <a...@lovetour.info> wrote: >> So if redim preserve will only let you extend the column value which >> I do not get as that is almost never what anyone would want, can you >> transpose the array, do the redim, then transpose back? > > The concept of row and column is a worksheet concept. In VBA an array > doesn't have a "physical orientation" like that. In fact, an array can have > a dozen dimension if needed or wanted. It's more of a tree (branching / > parent-child, etc.) concept than row and column in VBA > > The reason for the REDIM PRESERVE restriction is most likely related to the > way the array is arranged in memory. VBA can change the final dimension > "in-place" in memory without copying the whole array to a new memory > location. TRANSPOSE will create a new copy of the array (at least in vba -- > not necessarily with each use in a worksheet formula -- there I just don't > know). > > Yes, for a two dimensional array, transposing should let you redim the other > dimension, and transposing again will get you your originial array > arrangement with the preserved data. At the cost of copying the array in > memory twice. > > Asa > > -----Original Message----- > From: Asa Rossoff [mailto:a...@lovetour.info] > Sent: Wednesday, April 11, 2012 6:51 PM > To: 'excel-macros@googlegroups.com' > Subject: RE: $$Excel-Macros$$ Argh. Previously posted evaluate function > replacing loop has unnoticed major error > >> Whatever would make you think of it that being the case? > Sorry, makes me think of what being the case? > > -----Original Message----- > From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] > On Behalf Of Domain Admin > Sent: Wednesday, April 11, 2012 6:18 PM > To: excel-macros@googlegroups.com > Subject: Re: $$Excel-Macros$$ Argh. Previously posted evaluate function > replacing loop has unnoticed major error > > Whatever would make you think of it that being the case? > > So if redim preserve will only let you extend the column value which > I do not get as that is almost never what anyone would want, can you > transpose the array, do the redim, then transpose back? > > On Wed, Apr 11, 2012 at 6:10 PM, Asa Rossoff <a...@lovetour.info> wrote: >> rounding a range results in an array. Evaluate evaluates array formulas > and >> returns array results. So, the fact that it didn't with the simple ROUND >> formula is strange. transpose switches rows for columns, and a second >> transpose switches them back. So you get the original array. No idea why >> this was needed.. >> >> -----Original Message----- >> From: excel-macros@googlegroups.com [mailto:excel-macros@googlegroups.com] >> On Behalf Of Domain Admin >> Sent: Wednesday, April 11, 2012 6:02 PM >> To: excel-macros@googlegroups.com >> Subject: Re: $$Excel-Macros$$ Argh. Previously posted evaluate function >> replacing loop has unnoticed major error >> >> Ok that does appear to work, but I don't get it. How does nested >> transposes function >> to make this work correctly? It would appear to the novice that all >> you did was transpose >> it then transpose it back then whatever... >> >> Is transposing an array the answer to my other new post about redim >> preserve? >> >> On Wed, Apr 11, 2012 at 5:53 PM, Asa Rossoff <a...@lovetour.info> wrote: >>> To retrieve a multi-column array I resorted to >>> "transpose(transpose(round(a1:b10,2)))" form. >>> >>> >>> >>> From: Asa Rossoff [mailto:a...@lovetour.info] >>> Sent: Wednesday, April 11, 2012 5:18 PM >>> To: 'excel-macros@googlegroups.com' >>> Subject: RE: $$Excel-Macros$$ Argh. Previously posted evaluate function >>> replacing loop has unnoticed major error >>> >>> >>> >>> Hi Howard, >>> >>> Seems like an Excel bug.. Sorry for not testing the suggestion. Evaluate >>> may not be fully documented for a reason. However, it is a great useful >>> function, just if you aren't getting the result you expect, you may have >> to >>> look for a workaround. I just posted a query in a developers forum with >>> aomse big hitters to see if I can get an explanation for what you're >> seeing, >>> but in the meantime, here is a workaround. >>> >>> >>> >>> 1. What you've seen with your use of Evaluate is evaluate returning >>> only a single value -- the first value in the array, rather than the > whole >>> array as Evaluate usually does. >>> >>> 2. The INDEX function can be use to extract a reference to any >>> position in an array, or a whole row or column from an array. >>> >>> 3. Here is a modification of your statement that works in my test > by >>> using index to specify to return the first column from the array (which > of >>> course is the whole array in this case): >>> >>> tmprange.Value2 = .Evaluate("index(round(" & tmprange.Address & > ",2),,1)") >>> >>> >>> >>> I used Value2 since it's usually faster, but you can use Value if you >>> prefer. INDEX is the relevant change. >>> >>> >>> >>> Asa >>> >>> >>> >>> From: excel-macros@googlegroups.com > [mailto:excel-macros@googlegroups.com] >>> On Behalf Of tangledweb >>> Sent: Wednesday, April 11, 2012 2:28 PM >>> To: excel-macros@googlegroups.com >>> Subject: $$Excel-Macros$$ Argh. Previously posted evaluate function >>> replacing loop has unnoticed major error >>> >>> >>> >>> I used the evaluate function below to replace the commented out loop >> portion >>> for better performance in rounding off all the cells in a range. >>> >>> It was certainly fast and it performed the round function correctly but > it >>> also replaced every single cell in the range with the value of the first >>> >>> cell (ok you can laugh now). Any idea what is wrong with it? Kind of >> hard >>> to debug a single line of code. >>> >>> >>> >>> With Sheets(RawData) >>> Set tmprange = .Range(.Cells(2, 3), .Cells(stoprawdata, 7)) >>> tmprange.Value = .Evaluate("round(" & tmprange.Address & ",2)") >> 'use >>> evaluate instead of code below >>> ' For Each onecell In tmprange >>> ' onecell.Value = WorksheetFunction.Round(onecell, 2) >>> ' Next onecell >>> End With >>> >>> -- >>> FORUM RULES (986+ members already BANNED for violation) >>> >>> 1) Use concise, accurate thread titles. Poor thread titles, like Please >>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice >> will >>> not get quick attention or may not be answered. >>> >>> 2) Don't post a question in the thread of another member. >>> >>> 3) Don't post questions regarding breaking or bypassing any security >>> measure. >>> >>> 4) Acknowledge the responses you receive, good or bad. >>> >>> 5) Cross-promotion of, or links to, forums competitive to this forum in >>> signatures are prohibited. >>> >>> NOTE : Don't ever post personal or confidential data in a workbook. Forum >>> owners and members are not responsible for any loss. >>> >>> >> > ---------------------------------------------------------------------------- >> -------------------------- >>> To post to this group, send email to excel-macros@googlegroups.com >>> >>> -- >>> FORUM RULES (986+ members already BANNED for violation) >>> >>> 1) Use concise, accurate thread titles. Poor thread titles, like Please >>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice >> will >>> not get quick attention or may not be answered. >>> >>> 2) Don't post a question in the thread of another member. >>> >>> 3) Don't post questions regarding breaking or bypassing any security >>> measure. >>> >>> 4) Acknowledge the responses you receive, good or bad. >>> >>> 5) Cross-promotion of, or links to, forums competitive to this forum in >>> signatures are prohibited. >>> >>> NOTE : Don't ever post personal or confidential data in a workbook. Forum >>> owners and members are not responsible for any loss. >>> >>> >> > ---------------------------------------------------------------------------- >> -------------------------- >>> To post to this group, send email to excel-macros@googlegroups.com >> >> -- >> FORUM RULES (986+ members already BANNED for violation) >> >> 1) Use concise, accurate thread titles. Poor thread titles, like Please >> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice > will >> not get quick attention or may not be answered. >> >> 2) Don't post a question in the thread of another member. >> >> 3) Don't post questions regarding breaking or bypassing any security >> measure. >> >> 4) Acknowledge the responses you receive, good or bad. >> >> 5) Cross-promotion of, or links to, forums competitive to this forum in >> signatures are prohibited. >> >> NOTE : Don't ever post personal or confidential data in a workbook. Forum >> owners and members are not responsible for any loss. >> >> > ---------------------------------------------------------------------------- >> -------------------------- >> To post to this group, send email to excel-macros@googlegroups.com >> >> -- >> FORUM RULES (986+ members already BANNED for violation) >> >> 1) Use concise, accurate thread titles. Poor thread titles, like Please > Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will > not get quick attention or may not be answered. >> >> 2) Don't post a question in the thread of another member. >> >> 3) Don't post questions regarding breaking or bypassing any security > measure. >> >> 4) Acknowledge the responses you receive, good or bad. >> >> 5) Cross-promotion of, or links to, forums competitive to this forum in > signatures are prohibited. >> >> NOTE : Don't ever post personal or confidential data in a workbook. Forum > owners and members are not responsible for any loss. >> >> > ---------------------------------------------------------------------------- > -------------------------- >> To post to this group, send email to excel-macros@googlegroups.com > > -- > FORUM RULES (986+ members already BANNED for violation) > > 1) Use concise, accurate thread titles. Poor thread titles, like Please > Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will > not get quick attention or may not be answered. > > 2) Don't post a question in the thread of another member. > > 3) Don't post questions regarding breaking or bypassing any security > measure. > > 4) Acknowledge the responses you receive, good or bad. > > 5) Cross-promotion of, or links to, forums competitive to this forum in > signatures are prohibited. > > NOTE : Don't ever post personal or confidential data in a workbook. Forum > owners and members are not responsible for any loss. > > ---------------------------------------------------------------------------- > -------------------------- > To post to this group, send email to excel-macros@googlegroups.com > > -- > FORUM RULES (986+ members already BANNED for violation) > > 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, > Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not > get quick attention or may not be answered. > > 2) Don't post a question in the thread of another member. > > 3) Don't post questions regarding breaking or bypassing any security measure. > > 4) Acknowledge the responses you receive, good or bad. > > 5) Cross-promotion of, or links to, forums competitive to this forum in > signatures are prohibited. > > NOTE : Don't ever post personal or confidential data in a workbook. Forum > owners and members are not responsible for any loss. > > ------------------------------------------------------------------------------------------------------ > To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (986+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com