Help with using command buttons

laxminarayana

Board Regular
Joined
Nov 16, 2013
Messages
56
Hi,

I have placed two command buttons in "sheet1" each of which will insert some text into a cell in Sheet2. The problem is that when i click two command buttons one after the other, I don't see two sentences in cell (Sheet2)

Following is the code that i have assigned to "commandbutton1"

Sub autotext()
If Worksheets("Sheet1").Range("B1").Value = Worksheets("Sheet1").Range("B3").Value Then
Worksheets("Sheet2").Activate
Range("D1").Select
Range("D1").Value = "This is sentence one" & vbNewLine & vbNewLine

Else
Worksheets("Sheet2").Activate
Range("D1").Select
Range("D1").Value = "N/A sorry" & vbNewLine & vbNewLine
End If
End Sub

And Following is the code that i have assigned to "commandbutton2"

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

Thanks in Advance.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try

Code:
Sub autotext2()
With Worksheets("Sheet2").Range("D1")
    .Value = .Value & vbNewLine & "This is second sentence" & vbNewLine & vbNewLine
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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