+ Reply to Thread
Results 1 to 8 of 8

faux versioning

  1. #1
    Registered User
    Join Date
    04-01-2009
    Location
    WashDC
    MS-Off Ver
    Excel 2003
    Posts
    84

    faux versioning

    I would like to save/backup/version a few columns of a worksheet as it goes through a bunch of revisions. I can think two approaches: 1) a macro button that copies those few columns to the next available columns of another worksheet, and perhaps date-stamps them -- so every time a revision cycle is finished, the user punches the button and saves the columns; or 2) perhaps every time the file is saved (and those columns have changed?), it would run the same macro automatically: that's more elegant.

    Anyone have any other thoughts on this, and/or code? Is there a better way to do it?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: faux versioning

    Or maybe use SaveCopyAs in the BeforeSave event handler to make a copy of the entire workbook? You could date and time stamp the copy file. Then you have the data in context. If you save the changed columns in the same workbook, it is open to change/corruption as it is just another worksheet. And, if anything happened to the file, you lose everything.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: faux versioning

    Hi,

    I'd definitely use the automated version so that version column backups are made when necessary whenever the Workbook Save event is triggered.
    The trick will be deciding whether columns have changed.

    One way would be to copy the relevant columns and paste them as values to a temporary sheet whenever the Workbook Open event is triggered on loading the file. Then in the temporary sheet you could have formulae which compare each cell in the temporary sheet with the equivalent cell in the original sheet. e.g

    =IF(A1='MainSheet'!A1,0,1)

    On this temporary sheet have a single 'Check' cell that Sums the values of the comparison cells. When the Workbook Save event is triggered then this would read the value of the Check cell and if it's not zero (indicating at least one cell has changed) then it would proceed to copy the relevant values to the next set of columns on the Version Backup sheet. The header for each set of copied and pasted columns could be the system date. i.e. the macro would use =A1=Now as a date/time stamp.

    You'll need to consider what should happen if the workbook is saved more than once in a session. Do you want to keep any intermediate changes (probably not) or just the final session change.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: faux versioning

    ...and reflecting on TMS's comment which is a good suggestion, if you don't want to save the whole workbook, you could save a copy of the Version Backup sheet I mentioned as a separate file.

  5. #5
    Registered User
    Join Date
    04-01-2009
    Location
    WashDC
    MS-Off Ver
    Excel 2003
    Posts
    84

    Re: faux versioning

    Thanks for all the quick replies! I think saving within the workbook is going to be the way to go, this is a file that bounces back and forth between people and organizations, and so having other files associated with it is a recipe for disaster.

    I like the idea of
    1) Copy relevant columns to temp location on start/open
    2) Compare those with current contents at close
    3) If different: Copy to next available column on versioning worksheet, with datestamp

    I think that does it. I think there's some clever way to get the last-used column in a worksheet? Anyway, I'll take a stab at this and come back with more questions. If I'm missing anything or going down a problematic road here, let me know!

    Keith

  6. #6
    Registered User
    Join Date
    04-01-2009
    Location
    WashDC
    MS-Off Ver
    Excel 2003
    Posts
    84

    Re: faux versioning

    I'm stuck trying to cycle through the columns and rows of a given range: what I want to do is cycle through a handful of columns, and then loop down to the end of each column doing comparisons with a different column. Anyway, this is clearly not right semi-psuedo-code:

    For Each TCol In Range("D8:K129").Columns
    For Each Cell In TCol.Rows
    'If CompareCols(OrigCols, CurrCols) Then
    'Copy relevant columns & date stamp
    'End If
    Next
    Next

  7. #7
    Registered User
    Join Date
    04-01-2009
    Location
    WashDC
    MS-Off Ver
    Excel 2003
    Posts
    84

    Re: faux versioning

    In thinking about this, I realize I just need to run some indices through the range limits, and use offsets. I'll hit it tomorrow and come back with some more questions. I'm still a little curious to why the above code doesn't work-ish.

    K

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: faux versioning

    I'd avoid loops wherever you can and where standard excel functionality is available use that. Loops are inherently slow, particularly if you don't read all the data first into a VBA array and process them entirely within VBA. That's becuase Excel has to jump backwards and forwards between VBA and the Excel app at each iteration and there is a large time overhead involved.

    The fastest way I know of doing the stuff you suggest is to use an Advanced Filter which will filter out the data you're interested in logging in fractions of a second.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Faux MsgBox as vbModeless
    By MisterPan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2014, 09:15 AM
  2. [SOLVED] Versioning in Excel
    By Dave M in forum Excel General
    Replies: 0
    Last Post: 01-17-2006, 12:35 PM
  3. File Versioning in Excel???
    By Aimster in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2005, 06:05 PM
  4. Versioning Management
    By Arturo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1