how would I attach your code to a userform button? I have created the userform and the button but don't know how to attach your code to it.
Main Topics
Browse All TopicsCould you please advise what the code would be for the following actions I require.
Delete the text or numeric value from the current selected cell. (the selected cell will be Relative not Absolute)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
in the code behind of your spread sheet enter the following code.
Option Explicit
Public selected As Range
' this part puts the selected range of cells to be deleted into the variable 'selected' no quotes.
Private Sub Worksheet_SelectionChange(
Set selected = Target
' then this part displays your user form with the button on it.
UserForm1.Show
End Sub
in the userform, Button_Click event enter this code.
Option Explicit
Private Sub CommandButton1_Click()
'when you click the button the event fires and deletes the selected cell.
Sheet1.selected.Delete
End Sub
Your question statements seem to conflict. If it is the current selected cell then you have the absolute reference.
You can delete the contents of the current selection with
Selection.ClearContents
Or, if you want to just clear the current cell
ActiveCell.ClearContents
Or you can make a relative reference to the currently selected cell like this
ActiveCell.Offset(1,1).Cle
The offset is of the format (row,col) so the preceeding code clears the contents 1 row down and 1 column over from the active cell.
Hello Sir,
Check the following site if it can help you
http://www.exceltip.com/st
say range is as follows
Range("A1:C15").Select
For Each cl In Selection.Cells
cl.ClearContents
Next cl
with regards,
padmaja.
Business Accounts
Answer for Membership
by: BobLambersonPosted on 2006-10-07 at 20:47:08ID: 17684971
in the code behind the worksheet
ByVal Target As Range)
enter Target.Delete in the event for selection change
each time a cell is selected it will be deleted.
Private Sub Worksheet_SelectionChange(
Target.Delete
End Sub