+ Reply to Thread
Results 1 to 6 of 6

Identifying changed rows

  1. #1
    Registered User
    Join Date
    03-03-2008
    Posts
    4

    Identifying changed rows

    I have an Excel spreadsheet from which I import data into SQL Database.
    From time to time users make changes in the spreadsheet, changing values in certains columns of certain rows. How could I programmatically (using MS Visual Studio 2003, VB) identify those altered rows and import only them in the Database? Excel spreadsheet is faily big so brute force comparison of all fields in all rows would take forever.
    Thanks a lot in advance!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello slonus,

    I can tell you the method in VBA, but not Visual Studio. Place a macro in the Worksheet_Change() event procedure for the worksheet to be monitored. Have the macro open a text file that logs the cell(s) that are changed. Additionally the logged on user's name and a time stamp could added too.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    03-03-2008
    Posts
    4
    That sounds like a good plan. Would you happen to have a code sample I could use?
    Your help is greatly appreciated!

  4. #4
    Registered User
    Join Date
    03-03-2008
    Posts
    4
    Quote Originally Posted by Leith Ross
    Hello slonus,

    I can tell you the method in VBA, but not Visual Studio. Place a macro in the Worksheet_Change() event procedure for the worksheet to be monitored. Have the macro open a text file that logs the cell(s) that are changed.
    Sincerely,
    Leith Ross
    Hello, Leith!
    I did just that and it works fine. Except for the fact that it logs any changes done to the spreadsheet. Is there a way to ensure that only changes to the already EXISTING rows are logged in the text file?
    Thanks in advance!

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello slonus,

    Hopefully this code sample will help. Here is an example that constrains the logging to only cells in the range "A1:D10" of the active worksheet.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  6. #6
    Registered User
    Join Date
    03-03-2008
    Posts
    4
    Hello, Leith!
    Thanks a lot for your help!
    This code sample looks good.
    I have a few extra questions though:
    Is it possible to set the Range programmatically to whatever worksheet range is at the moment we open it for edit?
    How can we distinguish in our code between edits done to individual cells in exising rows (when row itself remains in the worksheet) and deletions of rows done either by highlighting the whole row and pressing "Delete" or by deleting content of every individual cell in the row? Will these deletions generate series of same events as editions and eventually be logged in the log file?
    If that is the case, can they be logged somewhat differently so I could distinguish between them later, when the file is read?
    An the last thing: what is the effect of doing "Undo" ? How is it treated?

    Leith, I really appreciate your taking time and helping me with this problem!
    Best regards, Slonus.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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