Delete Sheet When Corresponding Row in UserForms is Deleted

Chris96

New Member
Joined
Dec 17, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

New to VBA. I created this workbook over the last 24 hours by watching youtube videos and have no prior vba or coding experience.

The purpose of this workbook is for client management. I've created macros to add/update/delete clients from the "summary" sheet using a form. Once a client is on the summary list, I can automatically create a unique detail sheet for them using the "Create Client Detail Sheet" macro button and the sheet is automatically named using the client's name "Lastname, Firstname & Firstname".

What I want to be able to do is, when I am in the add/update/delete userform and I select a client and hit delete, I want their corresponding client detail sheet to delete as well. Is this possible?

Below are the current lines of code that correspond to the delete button being clicked. I don't even know how to attempt updating for what I want. Not sure if this is all you will need or not. Again I'm very new to this. Any guidance is appreciated.

VBA Code:
Private Sub buttonDelete_Click()
    If MsgBox("Are you sure you want to delete this client?", vbYesNo, "Delete Client") = vbYes Then
        Call DeleteRow(listboxClientInfo.ListIndex)
    End If
End Sub

Public Sub DeleteRow(ByVal row As Long)
    Sheets("Summary").Range("A6").Offset(row).EntireRow.Delete
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Chris, i don't know what cell you are storing the Client name in, if its in Column A of your selected row then try this.

VBA Code:
Application.DisplayAlerts = False
Sheets(CStr(Range("A6").Offset(row, 0))).Delete
Application.DisplayAlerts = True

-hth,
Ross
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,974
Members
449,095
Latest member
Mr Hughes

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