Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i want to create a button in excel that will clear the contents of the row without deleting the formulas

I think we need a little more detail before we can help.
As per the VBA Help files, formulae are content.
ClearContents Method
Clears the formulas from the range. Clears the data from a chart but leaves the formatting.What exactly are you trying accomplish?

We have a spreadsheet that oulines by program and color the parts that our required for shipment. When the quantities are satisfied, I want to be able to hit a clear button to the clear the contents of the specific row to be able to enter in new requirements. I have created a clear button but it is unique to that row. Do I need to create a separate macro for each row or can I create 1 macro that is "smart" to the row I create a button for. I am trying not to have to creat 50 individual macros to clear 50 different rows. Your ideas/help would be appreciated

You can create one button that will clear the currently selected row (or row that the currently selected cell is in), or you could create a button that asks you what row to clear or you could create a button to search for user-entered text and then clear that row, like a part number or etc. etc. You could even create a button that will clear only specific cells in a row.
The possibilites are almost endless, some are just more complicated than others.
However, your second post still doesn't clarify your original request: "clear the contents of the row without deleting the formulas".

disregard my first question Im beginning to understand the premise about clearing.You are deleting the text, not the cells. Thanks for the suggestions. How would I go about creating a button to ask what row I wanted to clear.

You would use the InputBox method. This is not something you can record, you have to either write the code from scratch or modify code created by the recorder.
Here is a simple example. Paste the code into a VBA editor window, place your cursor on the word InputBox and hit F1. This will open the help window for the InputBox method and explain how it works.
Sub ClearMyRow() 'Get Row Number MyRow = Application.InputBox("What Row Number Do You Want to Clear?", "My Row Clearer", Type:=1) 'Close Box If User Cancels If MyRow = False Then Exit Sub 'Clear the Row Rows(MyRow).EntireRow.ClearContents End Sub

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |