This is probably pretty simple to do but i'm still not totally sure how. I need a button that deletes selected text in excel, pretty much the same way as you would select a text and press delete on your keyboard.
-
Can you not just press the delete button? Could you expand a little more on your question, maybe give an example of the process and what happens.NickSlash– NickSlash2013-08-11 18:54:20 +00:00Commented Aug 11, 2013 at 18:54
-
Well let's say you got some text in cells a1, a2, a3. You select them and press a delete button on a keyboard and the text is deleted. what i want is a virtual button in excel. Here's the code i have Sheets("Baza").Range("").Clear The problem is that i dont know what to type as a location in code so the computer knows that it must delete selected cells.Blue Norris– Blue Norris2013-08-11 19:15:30 +00:00Commented Aug 11, 2013 at 19:15
-
can you explain how your desired behaviour would be any different to pressing delete (button on ribbon or on keyboard)? Not sure I understand the issue ;)Cor_Blimey– Cor_Blimey2013-08-11 20:02:03 +00:00Commented Aug 11, 2013 at 20:02
-
well it is kinda pointless but i'm playing around in excel and i was wondering if it's possible to do this.Blue Norris– Blue Norris2013-08-11 20:09:51 +00:00Commented Aug 11, 2013 at 20:09
-
2@BlueNorris In that case, if you are playing around to learn stuff, try playing around with the macro recorder - it can be a good way to begin to learn about some of the objects. Also, open up the object browser in the VBE and look at some of the main objects like Workbook, Worksheet, Range. It will show all the properties and methods of the objects and give you an idea about what you can do with each (lots..!).Cor_Blimey– Cor_Blimey2013-08-11 22:58:33 +00:00Commented Aug 11, 2013 at 22:58
Add a comment
|
2 Answers
You can add a button to the worksheet from the Developers tab, using a simple Form Control. Selection.Clear or Selection.ClearContents will.. clear everything, or just the contents, from the current selection:
Sub Button1_Click()
Selection.Clear
End Sub
But presumably you want to be able to use this from anywhere, not just in a specific worksheet. In which case, create the Macro first and then Customize the Quick Access Toolbar to add a button to run the macro.
1 Comment
Andy G
Bearing in mind, of course, that you could just find a built-in button (from More Commands..) to add to the QAT that already does this.
Click on your text or cell where your text is written. Simply click del key from keyboard. or see below image for more details.

1 Comment
Blue Norris
Well i need an actual button for this. Here is the code. Sheets("Baza").Range("").Clear I dont know what to type as a location in code so the computer knows that it must delete selected cells.