vba Delete Row and Member

RasGhul

Well-known Member
Joined
Jul 15, 2016
Messages
797
Office Version
  1. 365
Platform
  1. Windows
Hi Team,

I have a 200 member data set columns A:I and a combo box with the members names DV. When I select someones name from the combo box I would like to delete that row from A:I. I was tinkering with the selection.delete shift:= xlUp function but couldn't define the needed objects etc. it works when I record a macro but I would like to be able to delete who I select from the Combo box.


Thanks in advance all.

:cool:
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Record the macro and post the code, it's a good way to understand what you want your sheet to do, without benefit of seeing your PC screen.

Is there only ever 1 unique name or duplicates? If duplicates, have you considered filtering your data for that name and then deleting those rows? Again, record the macro to do this and post that code.

Also, state the name of the sheet, as usually this isn't clear from the recorded macro if you're not changing sheets.
 
Upvote 0
Thanks Jack for the reply

So I've mapped the row addresses and as the Combobox1 value changes to different members names the L2 value is the address that needs to be deleted like in the 'recorded macro("A9:F9"). The vba needs to read the value from L2 and select that for delete.

Sorry I realize it would be easier just to right click and delete the row, but I'm trying to make this sheet easier for the owner...


Code:
Private Sub ComboBox1_Change()


Sheets("Members").Range("H2").Value = Me.ComboBox1.Value


End Sub


Private Sub CommandButton1_Click()


' delmember2 Macro
'
Dim r As Range
Dim sta As String


Set r = Sheets("MEMBERS").Range("L2").Value


    sta = r.Value.Select
    
'recorded macro
    Sheets("MEMBERS").Range("A9:F9").Select
    Selection.Delete Shift:=xlUp
    Sheets("MEMBERS").Range("A6").Select
    
    
    Sheets("MEMBERS").Range("H2").ClearContents
    
    ThisWorkbook.RefreshAll
    


End Sub


Private Sub CommandButton2_Click()


    Unload Me


End Sub


Private Sub UserForm_Initialize()


Sheets("MEMBERS").Range("H2").ClearContents




End Sub
 
Last edited:
Upvote 0
Try this for Private Sub CommandButton1_Click which will delete all rows in A:F where row in A matches L2 (starting at A3 to the last row in column A):
Code:
Private Sub CommandButton1_Click()

' delmember2 Macro
Dim x   As Long
Dim LR  As Long

Application.ScreenUpdating = False

With Sheets("MEMBERS")
    LR = .Cells(.Rows.count, 1).End(xlUp).row
    For x = 3 To LR
        If .Cells(x, 1).Value = .Cells(2, 12).Value Then .Cells(x, 1).ClearContents
    Next x
    
    On Error Resume Next
    .Cells(3, 1).Resize(LR - 2, 6).SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
    On Error GoTo 0
    .Cells(2, 8).ClearContents
End With
    
ThisWorkbook.RefreshAll

Application.ScreenUpdating = True
    
End Sub
Untested, so save your work before running or make a copy of your workbook to test on.
 
Last edited:
Upvote 0
Thanks Jack, but I only want to delete one row that matches the L2 value so we can remove that member. As in the screenie below as we select names with the combobox the row range to delete is in L2. When I run vba in this case it should delete the row only from A9:F9. (I know the pic as H9 but I've deleted some columns since.)


 
Last edited:
Upvote 0
Try:
Code:
Private Sub CommandButton1_Click()

' delmember2 Macro
Dim x   As Long
Dim LR  As Long


Application.ScreenUpdating = False


With Sheets("MEMBERS")
    LR = .Cells(.Rows.count, 1).End(xlUp).row
    
    On Error Resume Next
    .Cells(3, 1).Resize(LR - 2).find(what:=.Cells(2, 8).Value, LookIn:=xlValues, lookat:=xlWhole).Resize(, 6).Delete shift:=xlUp
    On Error GoTo 0
    
    .Cells(2, 8).ClearContents
End With
    
ThisWorkbook.RefreshAll


Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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