Find user input and clear specific cells

Excel Ent

New Member
Joined
Aug 21, 2019
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Hello
I have a small project i'm trying to complete. What I am looking to do is the following:
1.) User enters the associate to remove from the list
2.) macro finds user in A and clears cells B,C,D,E,F. I need the range to stop at F because there are instructions in cells I,J,K so entirerow.delete will not work.


TEST.jpg
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
This should work

VBA Code:
Option Compare Text

Sub Remove_Employee()
'
    Dim Employee As Range
    Dim L As Long
        Sheets("Sheet1").Select
        L = ActiveSheet.Range("A1").End(xlDown).Row
        Set Employee = ActiveSheet.Range("A1:A" & L)
'
    Dim InBx As Variant
        InBx = Application.InputBox("Please enter the associate you want to remove")
'
    Dim i As Long
        i = Application.WorksheetFunction.Match(InBx, Employee, 0)
'
    Rows(i).EntireRow.Delete
'
End Sub
 
Upvote 0
This should work

VBA Code:
Option Compare Text

Sub Remove_Employee()
'
    Dim Employee As Range
    Dim L As Long
        Sheets("Sheet1").Select
        L = ActiveSheet.Range("A1").End(xlDown).Row
        Set Employee = ActiveSheet.Range("A1:A" & L)
'
    Dim InBx As Variant
        InBx = Application.InputBox("Please enter the associate you want to remove")
'
    Dim i As Long
        i = Application.WorksheetFunction.Match(InBx, Employee, 0)
'
    Rows(i).EntireRow.Delete
'
End Sub
Missed the entirerow.delete part

instead use Range(Cells(i, 1), Cells(i, 6)).delete Shift:=xlUP
 
Upvote 0
Solution
thanks for the quick response. Really appreciate it. When I run the code I get a runtime error 1004 on the following line
Set Employee = ActiveSheet.Range("A1:A" & M")
 
Upvote 0
Nevermind….I see the errors of my ways. Your are a gem... thanks for your time.
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,782
Members
449,123
Latest member
StorageQueen24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top