How to insert and delete text in a cell using command buttons

laxminarayana

Board Regular
Joined
Nov 16, 2013
Messages
54
Hello experts,

I have the following situation and trying to solve using vba.

I have few sentences in "sheet1". one in cell "B3" and other in cell "B9" and i have placed two command buttons named "Insert" and "clear" against each sentence, so that when ever "Insert" button is clicked the respective sentence will be copied in cell "D1" of sheet 2, and "clear" button to "clear" the respective sentence. When more than one sentence is inserted i am trying to have one line gap between them.

Please help with the code that is to be written in "Insert" and "Clear" buttons.

Thank You.
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

ZAX

Well-known Member
Joined
Jul 5, 2012
Messages
715
Hi Laximinarayana,
Use this to the Insert button for B3:
Code:
Sub Insert1()
Range("B3").Copy
Range("D1").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
End Sub
And this for the Clear button of B3:
Code:
Sub Clear1()
Range("B3").Clear
End Sub
And this to the Insert button for B9:
Code:
Sub Insert2()
Range("B9").Copy
Range("D1").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
End Sub
And this for the Clear button of B9:
Code:
Sub Clear2()
Range("B9").Clear
End Sub
Hope that helps and works as expected.
ZAX
 

laxminarayana

Board Regular
Joined
Nov 16, 2013
Messages
54
Hi Laximinarayana,
Use this to the Insert button for B3:
Code:
Sub Insert1()
Range("B3").Copy
Range("D1").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
End Sub
And this for the Clear button of B3:
Code:
Sub Clear1()
Range("B3").Clear
End Sub
And this to the Insert button for B9:
Code:
Sub Insert2()
Range("B9").Copy
Range("D1").PasteSpecial (xlPasteAll)
Application.CutCopyMode = False
End Sub
And this for the Clear button of B9:
Code:
Sub Clear2()
Range("B9").Clear
End Sub
Hope that helps and works as expected.
ZAX


Thank you. The code you have sent is working, but the result is not as expected.
I think i have posted my question in wrong manner. Can you please have a look at the following code and tell how to achieve the desired result.

Command button1 is assigned with a macro with following code:

Sub autotext()
Worksheets("Sheet2").Activate
Range("D1").Select
Range("D1").Value = "This is sentence one" & vbNewLine & vbNewLine
End Sub

Command button2 is assigned with a macro with following code:
Sub autotext2()
Worksheets("Sheet2").Activate
Range("D1").Select
Range("D1").Value = "This is second sentence" & vbNewLine & vbNewLine
End Sub

Similarly i have other buttons too. when i click two or three command buttons i don't get multiple lines in cell "D1".
Following is the result that i am trying to get

http://s29.postimg.org/bps3xdtdz/Untitled.png


Thank You.

 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,653
Members
414,083
Latest member
Mrsash

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
Top