+ Reply to Thread
Results 1 to 29 of 29

Search for and Update changes Only

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Search for and Update changes Only

    Hi Guru's

    Need help in creating a Macro that updates data in several worksheets.


    My data is added on "Sheet1" via a range of validations.

    How it works:

    I add my Name (Rick) and staff number (123456) (this will be the unique reference), I then select a system by a drop down box which populates a range of sub systems. I then select my level of experience of every sub system within the system I selected.

    I then click the add button and a macro sends the data I entered to that Systems worksheet in a single row (colume A will be the name colume B will be the staff number) all other data spreads out on C,D all the way to Colume Q.

    When the next staff's details are entered, and for the same system, their details will move to the next row down on the worksheet.


    WHAT I WANT IT TO DO.... is if for example I enter my deatils again for the same System, I want it to find my staff number and replace only the changes made in that row. Currently it is adding a new row of data.


    Anyone want a challenge?


    Heres my Macro
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 09-06-2012 at 08:31 PM. Reason: Added Code Tags

  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

    Re: Search for and Update changes Only

    Hello RicktheBlade,

    I placed your code in a code window by using the code tags. To do this, select all of your code and then click the icon that looks like this #
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    I trimmed your code a bit - I'm not sure that I've addressed your problem:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Cheers Leith, I now know for the future.

  5. #5
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Thanks XLAdept, very nicely trimmed. Still trying to get it to search for an existing enty and update where relevant.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    You're welcome - how can relevance be established?

  7. #7
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    I want this marco to check if "Staff Number" exists. If exists rewrite row with changes made, if "Staff Number" dont exist = new row

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    Hi RicktheBlade,

    Where is "Staff Number"?

  9. #9
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Hi XLAdept,

    "Staff Number" is located in colume "B" of certain sheets. All Staff members data is gathered in rows, the staff number is the unique identifier

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    I can't picture it - can you post an example? What are the "certain sheets" - I can see only "Sheet1" and "Data" and several colors?

  11. #11
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Hi XLAdept,

    I am unable to add an attachment due to mu employments security. So will explain as well as I can.

    In my workbook I have 16 sheets. "Sheet1" is my data entry sheet. This sheet works off a varity of validations.

    B3 = Name (No Vallidation)
    B4 = Staff Number (No Vallidation)
    B5 = Role
    B6 = Employment

    B10 = System i.e red, blue, green, yellow, and so on (These each have there own sheet within the workbook)

    B12 - B33 are all vallidations of level of experiance against the Sub System selected in B10.

    I have an add button that once clicked sends the data i have entered to the system selected (B10) sheet. e.g if I add my name and staff number, select my role, and employment. Then select the system i.e Red (this will display all the subsystems Red has), then I select my level of experiance of each of those subsystems. I click the add button and all this data is added to Sheet!"Red" in a single row, name in A2,Staff number in B2, Role C2, Employment D2, System E2, 1st Subsystem F2, 2nd Subsystem G2, and so on.

    If another staff member enters there details on the same system ("Red"), their data is added to Sheet!"Red" also, but on the next row.

    At the moment if I add my details for System "Red" it will add to Sheet!"Red" (as expected), but if I add more details for the same system ("Red") it will add another row as if I was another staff member.


    What I want it to do is update (say if I have just increased my experiance on one of "Reds" subsystems. Meaning I will always only have one entry on Sheet!"Red" for each staff member, but it gets updated as experiance increase.

    Now what I was thinking was adding a piece of code to the marco I have earlier on in this thread (Sub.Button 2 Click) to look for my staff number Sheet1!B4 and Sheet1!B10 in the selected systems sheet in Sheet1!B10 , and if that combination exist, relace the new input on my row within that systems sheet with the new data, modifying only the cells that have been updated. If the staff and system combination does not exist, add the new row.


    If you can help me with this piece of code, I can try and write the rest. Thanks heaps. Rick

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    I can't envision a way to make it retain the "old" row - I'll look again later.

  13. #13
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Neither, maybe somthing that replaces cells .

    So the code would have to look at if the cell has changed excluding colume B, if it has, replace with new data, if not ignor etc

    Heres an example of what it is doing now (columes A - K) top 4 rows are added from Sheet1! End goal is to get the single row to update to look like the 5th row below. So the code would have to look at if the cell has changed, if it has, replace with new data, if not ignor.
    Rick 1234 Manager Permanent Red Advanced Beginner Beginner Advanced Beginner
    Rick 1234 Manager Permanent Red Competent
    Rick 1234 Manager Permanent Red
    Rick 1234 Manager Permanent Red Novice Expert Expert Expert


    Rick 1234 Manager Permanent Red Novice Expert Expert Expert Advanced Beginner

  14. #14
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Copy of Latestv3.xls

    Managed to send to my home PC


    Once I get the data updating, i then need to work on the "Search" sheet to return the data requested from these sheets.


    All help apprieciated
    Last edited by RicktheBlade; 09-11-2012 at 03:29 AM.

  15. #15
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Has anyone got an idea of how I can do this?

  16. #16
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    Hi RicktheBlade,

    Try This:

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Hi XLAdept,

    Thanks, but It is still adding a new row as before.

  18. #18
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    Hi Rickthe Blade,

    I'll try to write a NewRow function tomorrow!

  19. #19
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Awesome, thanks XLAdept, I really apprieciate your help with this

  20. #20
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    Hi RicktheBlade,

    I added the NewRow algorithm as a subroutine - try it and let me know what else needs fixed:

    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Hi XLADept,

    This has stoped adding the new row and overwrites the correct row in the sheets.

    Now I just need it to replace only what has changed.

    Say if Rick 123456 exist in sheet Red and is good in columes F,G, and H, and then he becomes an Expert in colume G, the end result will have F "Good", G"Expert, and H"Good". At he moment it will overight and will only have colume G "Expert"

  22. #22
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    Maybe:

    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    This will add the new data if the cell is blank, but if the cell is not blank it will ignor it and not replace.

    Also if the staff member (Staff number") does not exist in sheet"Red" I get the runtime 91 error. But if I leave the staff number blank it will instert the new staff member


    "Getting close"
    Last edited by RicktheBlade; 09-13-2012 at 05:13 PM.

  24. #24
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    XLAdept, thanks very much for your help. With the code you provided I was able to fix the rest, see below.

    Thanks again, your a star

    HTML Code: 

  25. #25
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    Hi RicktheBlade,

    I've changed a bit of the code - it might fix an issue down the road - glad you've got it working!

    Please Login or Register  to view this content.

  26. #26
    Registered User
    Join Date
    08-30-2012
    Location
    NZ
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Search for and Update changes Only

    Awesome, thanks again

  27. #27
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    You're welcome - (I'm toying with the idea of further trimming.)

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Search for and Update changes Only

    Hi RicktheBlade,

    This is ready now:

    Please Login or Register  to view this content.
    Last edited by xladept; 09-14-2012 at 07:00 PM. Reason: Tweak

  29. #29
    Registered User
    Join Date
    09-24-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Search for and Update changes Only

    which is exactly what I want to do upon transfer from my userform to my one sheet in a different workbook. I have written the code for the transfer to the correct columns in my "host" sheet, but i want it to also do the above opperation based upon the most recent entry which I have coded with a timedate stamp.

    Rick 1234 Manager Permanent Red Advanced Beginner Beginner Advanced Beginner
    Rick 1234 Manager Permanent Red Competent
    Rick 1234 Manager Permanent Red
    Rick 1234 Manager Permanent Red Novice Expert Expert Expert


    Rick 1234 Manager Permanent Red Novice Expert Expert Expert Advanced Beginner

    Since all of my data is going to one sheet, I just cant pick out the code from your previous work to make this happen. Im guessing the new code should be located in the "transfer procedure" as id like the "host" to be as read only as possible

    Im trying to just updated any previous data with new, or if new data comes in with blanks it does not overwrite the previous data

    Please Login or Register  to view this content.
    Let me know if there is anything else you need but the "host" data table is simple. just 27 columns and each one has its own controll on the userform. if its a new entry (by the way the Ref for this find/replace thing is column C and the second is column AA) then it goes into the new row, if not it does what i described above.

    Thanks

+ 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