Delete a row in a named range using userform delete button

charly1988

New Member
Joined
Jul 31, 2022
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
I have item sheet which has a named range call "ItemList" and it has 3 fields "productID, productName and productDescription" . All i want is delete a row in the named range using productID from userform. I have a delete button in my userform.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Assuming that the productID for which to search is coming from a textbox on the userform, try...

VBA Code:
    Dim foundCell As Range
    Set foundCell = Range("ItemList").Columns(1).Find(what:=TextBox1.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    If Not foundCell Is Nothing Then
        foundCell.EntireRow.Delete
    End If

However, if the named range has worksheet scope, replace...

VBA Code:
Set foundCell = Range("ItemList").Columns(1).Find(what:=TextBox1.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)

with

VBA Code:
Set foundCell = ThisWorkbook.Worksheets("Sheet1").Range("ItemList").Columns(1).Find(what:=TextBox1.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)

Hope this helps!
 
Upvote 0
Solution
Assuming that the productID for which to search is coming from a textbox on the userform, try...

VBA Code:
    Dim foundCell As Range
    Set foundCell = Range("ItemList").Columns(1).Find(what:=TextBox1.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    If Not foundCell Is Nothing Then
        foundCell.EntireRow.Delete
    End If

However, if the named range has worksheet scope, replace...

VBA Code:
Set foundCell = Range("ItemList").Columns(1).Find(what:=TextBox1.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)

with

VBA Code:
Set foundCell = ThisWorkbook.Worksheets("Sheet1").Range("ItemList").Columns(1).Find(what:=TextBox1.Value, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)

Hope this helps!
works so perfectly. Thank you very much sir. Hats off for your help
 
Upvote 0
For your new question, please start a new thread, and one or more of the many volunteers here on the Board will be happy to help.

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,598
Messages
6,120,441
Members
448,966
Latest member
DannyC96

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