create Button to Delete Rows, Please Help

paata01

New Member
Joined
May 10, 2014
Messages
21
Hello everyone,
can you please help me. I want to create Macro in VBA that will delete specific rows in excel. this is what I want to do
I am working on t-shirts excel file, I want to have two options there "MEN" and "Women", when I click men it should delete all woman rows. I have know specific rows which should be deleted. How can I do something like this? from filter it takes a lot of time to delete manually.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Thanks for quick reply, I want to completely delete rows, when I click "MEN" delete this this and this rows, I have row numbers I want to delete. and I want to have on restore button. To restore deleted rows, if possible.
 
Upvote 0
I created simple three buttons, MEN WOMEN RESTORE

Private Sub CommandButton1_Click()
Sub DeleteRow1()
Rows(2).Delete
End Sub


Private Sub TextBox1_Change()


End Sub


Private Sub CommandButton2_Click()


End Sub


This is the formula I got from google, first command is giving me error. what's wrong with it? and Restore button should undo action taken by MEN or WOMEN button. can somebody help...
 
Upvote 0
ok, I know how to delete specific rows. can someone help, what code should be under RESTORE BUtton to undo actions by other buttons. something like restore to default.
 
Upvote 0
You can't. There is no Undo for actions performed by a macro.

You should take Truiz's question to heart.

It seems you should just HIDE the rows insted of delete them.
 
Upvote 0
I prefer to hide, but once I save file as CSV will hidden rows be there? if not how can I do HIDE instead of DELETE and make restore button, to unhide.
 
Upvote 0
Yes, the rows will still be there in the CSV file, but they won't stay hidden.

Post the code you have that Deletes the rows, we can likely adjust it to Hide instead of Delete.
 
Upvote 0
Private Sub CommandButton1_Click()
Rows(38).Delete
End Sub
Private Sub CommandButton2_Click()


End Sub
Private Sub CommandButton3_Click()

End Sub


Private Sub UserForm_Click()


End Sub


This is the useform, with three buttons. as an sample I have just one DELETE rows (38), I work in (.xlsx) Format and save as CSV after finished. If Hidden rows won't be in CSV it would be perfect.
 
Upvote 0
Try changing
Rows(38).Delete
to
Rows(38).Hidden = True


and change True to False to UNhide the row.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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