Results 1 to 15 of 15

VBA to delete rows based on user input

Threaded View

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

    VBA to delete rows based on user input

    Apologies, I was not aware of the tags. I am not sure if I did it correctly but I did as I understood from your instructions.
    Thank you so much.

    Hi!

    I have this code to delete an employee based on the employee id a user inputs. I placed a note on the message box because I cannot figure out how I can delete several employee id inputs all at once.

    Can anybody help me add a command to delete multiple rows based on user input of employee id's (separated by semicolon)? It would also be cool to have a confirmation message like:

    The following employee id's were deleted from the list:
    123
    456
    789

    The following employee id's were not found:
    654
    321



    Sub delete_employee()
    Dim lastRow As Long, x As Long
    Dim resp
    resp = InputBox("Enter Id of employee to delete." & vbLf & "NOTE: This action can only be done one employee id at a time.", "Delete")
    If resp = "" Then Exit Sub
    MsgBox ("Are you sure you want to permanently delete this employee from the list?" & vbLf & 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

    Thank you so much for all your help!
    Last edited by Roux11; 05-25-2020 at 04:00 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Delete specific number of rows for each column with user input
    By Sriramroxx in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-22-2019, 11:28 AM
  2. [SOLVED] delete last character based on user input
    By k1dr0ck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2018, 10:44 PM
  3. Replies: 15
    Last Post: 07-11-2017, 10:55 AM
  4. [SOLVED] VBA to delete columns based on user input
    By Muktar888 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2017, 09:00 AM
  5. Macro to Delete Row based upon User Input Box value
    By Mike7591 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-18-2013, 10:02 AM
  6. Automatically Add/Delete rows based on user input but check current table row count
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-31-2011, 11:39 AM
  7. Delete rows based on user input
    By Militia in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-10-2009, 06:33 AM

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