Delete data from table using userform according to specific data

No_Taipe

New Member
Joined
Oct 3, 2018
Messages
2
Hi,

I'm working in a inventory system and i'm using a userform to add and delete data in a specific table containing all the information.

Right now i was able to make a macro to add information to the last blank cell of the table.

Code:
Private Sub CommandButton1_Click()    Dim rng As Range
Set rng = Sheets("LISTAGEM").ListObjects("Table1").Range
Dim LastRow As Long
LastRow = rng.Find(What:="*", _
After:=rng.Cells(1), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row


rng.Parent.Cells(LastRow + 1, 1).Value = TextBox2.Value
rng.Parent.Cells(LastRow + 1, 2).Value = TextBox3.Value






MsgBox "Portátil Adicionado"


If TextBox2.Text = "" Then
    MsgBox "Inserir EAN no campo indicado!"
    
    End If
    
End Sub



Now, what i need to know is, how can i delete data from the table using only the information in the "SKU" field of the userform?












EXAMPLE: If i have "1234" in the SKU field, and press "DELETE", the userform will search for "1234" in the table and erase that line.



Thanks in advance.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe something like this...

Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] CommandButton2_Click()
    [color=darkblue]Dim[/color] rng [color=darkblue]As[/color] [color=darkblue]Variant[/color]
    [color=darkblue]With[/color] TextBox2   [color=green]'SKU textbox[/color]
        [color=darkblue]If[/color] .Text <> "" [color=darkblue]Then[/color]
            [color=darkblue]Set[/color] rng = Sheets("LISAGEM").Range("A:A").Find(.Text, , xlValues, xlWhole, 1, 1, 0)
            [color=darkblue]If[/color] [color=darkblue]Not[/color] rng [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
                rng.EntireRow.Delete
                .Text = ""
            [color=darkblue]Else[/color]
                MsgBox .Text, vbExclamation, "No SKU Match Found"
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]Else[/color]
            MsgBox "SKU is missing.", vbExclamation, "Invalid Entry"
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,214,383
Messages
6,119,196
Members
448,874
Latest member
Lancelots

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