+ Reply to Thread
Results 1 to 28 of 28

VBA code to move entire row based on value/s from input box

  1. #1
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    VBA code to move entire row based on value/s from input box

    Hi!

    I would like to ask help on a VBA code to help me move an entire row to another worksheet based on a value (or multiple values) from an input box. For example I have a list of employees and I want to move one or several of them to the terminated sheet without going through the list one by one or searching by ctrl + F and then cut and paste to the terminated tab. I would like to have an input box where I can just put the employee id (or employee id's of there are more than one) and then it will find the employee from the active employees tab, cut the row and paste it to the terminated tab.

    I have attached a sample file.

    Your help is greatly appreciated!

    Regards,
    Roux11
    Attached Files Attached Files

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    As a starter.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA code to move entire row based on value/s from input box

    Try
    Please Login or Register  to view this content.
    Last edited by jindon; 05-17-2020 at 08:58 PM. Reason: Found a bug, code replaced.

  4. #4
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    works perfectly! Thank you so much!

    Can I have a message box pop out to confirm the employees that were moved to terminated and if there is an employee id that was not found in the list?
    Example:

    The following employee id's were moved to Terminated Tab:
    123
    456

    The following employee id's were not found:
    754
    543

    Thank you again

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Please Login or Register  to view this content.
    Last edited by bakerman2; 05-18-2020 at 02:41 AM. Reason: Added dot in front of Rows.....

  6. #6
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Thank you sir Jindon for your response

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA code to move entire row based on value/s from input box

    Have you tried the code after I edited?

  8. #8
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Thank you. This is perfect! I love this group!

  9. #9
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Not yet, sir Jindon. I will try to use it on another workbook. Thank you again.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Glad to help.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  11. #11
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Just a minor tweak needed. I used the code to the actual sheet with around 20 columns. It seems to be copying only 3 columns.

  12. #12
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    getting error 400 on your code, sir.

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Thank you! It is now working

    If I will do it in reverse (terminated tab to active tab), should I just interchange the tab names in the code?

  15. #15
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Short answer, "YES".

    Thanks for rep+.

  16. #16
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    If I just want to move 2 columns with data, how do I do that? From my example, if I want to move employee 123 to the terminated tab but I want the Name column to be blank for privacy.

  17. #17
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Thank you for the updated code. It works in omitting the name however it moves the city to the name column.

  19. #19
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Now why would you want an empty columns between your data if you have no intent on using it ???

  20. #20
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    I have the same set of column headers in the terminated sheet in which other reports are linked to so I do not want to remove any columns... just want to leave it blank.

  21. #21
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Sir, how do I keep just columns 1,5,9 & 15 when moving employee to terminated tab?

  22. #22
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Please Login or Register  to view this content.
    The 100 is just a columnnumber from which you're certain that it will never be used.
    You can change that to any number you would like.

  23. #23
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    I got it working. You are awesome! Thank you so much!
    Last edited by Roux11; 05-20-2020 at 05:30 PM. Reason: got it working

  24. #24
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    I got this code from another source and need to have the employee id show up on the message box like the one you made. With this code, the employee id shows right after the question mark. It would be better to have it like a list below the question especially if there are several employee id's to be deleted. I also love the notification you made that states what employee id's were deleted and the employee id's not found from the list.

    Sub delete_Me()
    Dim LastRow As Long, x As Long
    Dim resp
    resp = InputBox("Enter AC Id of rater to delete", "Delete")
    If resp = "" Then Exit Sub
    MsgBox ("Are you sure you want to permanently delete this employee from the roster?" & resp)
    LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
    If IsDate(resp) Then
    resp = CDate(resp)
    End If
    For x = LastRow To 1 Step -1
    If IsDate(resp) Then
    If Cells(x, "A").Value = resp Then
    Rows(x).Delete
    End If
    End If

    If Not IsDate(resp) Then
    If UCase(Cells(x, "A").Value) = UCase(resp) Then
    Rows(x).Delete
    End If
    End If
    Next
    End Sub

  25. #25
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Hi Excel gurus,

    Just a follow up on the code I received from you guys regarding moving entire rows based on user input. Everything works well, thanks to all of you. Upon testing a list of employee id's it was noticed that the id's below the one that wasn't found isn't processed. For example I entered 10 employee ids and the 5th one was not found in the sheet. The function stops there and does not process employee ids 6th to 10th. Is there any code that can be supplied to let the function continue along the list if there are id's not found in the sheet?

  26. #26
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Post a relevant example file with the current code you are using.

  27. #27
    Registered User
    Join Date
    05-17-2020
    Location
    Philippines
    MS-Off Ver
    2016
    Posts
    35

    Re: VBA code to move entire row based on value/s from input box

    Please Login or Register  to view this content.

  28. #28
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA code to move entire row based on value/s from input box

    Post an example file in which the error occurs because I can't find anything wrong with the code.

+ 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. Noob in need of VBA code to move entire row based on cell criteria
    By missmlsaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2019, 02:04 PM
  2. Move entire row of data to another worksheet based on a value
    By tjsmith1962 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-11-2018, 03:53 PM
  3. Move entire row from one sheet to another based on cell input
    By ChristianJ in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-01-2018, 11:31 PM
  4. Replies: 3
    Last Post: 01-01-2016, 04:07 AM
  5. Move an entire row to a new sheet based on the value of a cell.
    By jgroathouse in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-05-2014, 08:16 PM
  6. [SOLVED] Move entire row to another worksheet based on cell value
    By bdf0827 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 04-09-2014, 07:01 AM
  7. Move entire row to a new sheet based on cell value vba help
    By almasdour in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2013, 01:38 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