ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   New to Visual Basic (https://www.excelbanter.com/excel-discussion-misc-queries/209858-new-visual-basic.html)

Need help with sumif

New to Visual Basic
 
I wrote this simple task can anyone tell me how do I run this

Private Sub CommandButton1_Click()
Dim sName As String
sName = InputBox("Enter your name", "Title")
Cells.Value("A1") = sName
End Sub




Bob Phillips[_3_]

New to Visual Basic
 
You add a button to the worksheet and call it CommandButton1. Then you click
it.

--
__________________________________
HTH

Bob

"Need help with sumif" wrote
in message ...
I wrote this simple task can anyone tell me how do I run this

Private Sub CommandButton1_Click()
Dim sName As String
sName = InputBox("Enter your name", "Title")
Cells.Value("A1") = sName
End Sub






Mike H

New to Visual Basic
 
Hi,

A couple of syntax errors. This type of button is from the 'Control' toolbox
so with the syntax corrected simply click the button. the button must be out
of design mode. Click the icon that looks like a set-square to exit design
mode.

Private Sub CommandButton1_Click()
Dim sName As String
sName = InputBox("Enter your name", "Title")
Range("A1").Value = sName
End Sub


Mike


"Need help with sumif" wrote:

I wrote this simple task can anyone tell me how do I run this

Private Sub CommandButton1_Click()
Dim sName As String
sName = InputBox("Enter your name", "Title")
Cells.Value("A1") = sName
End Sub




Luke M

New to Visual Basic
 
First, remove the private from your macro, since you want to call it out via
a button (I assume).

Also, "Cells.Value("A1") = sName" is not valid. Change it to:
Cells(1,1).Value = sName

Using the Forms toolbar (NOT control), create a button. Then assign your
macro to the button.
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Need help with sumif" wrote:

I wrote this simple task can anyone tell me how do I run this

Private Sub CommandButton1_Click()
Dim sName As String
sName = InputBox("Enter your name", "Title")
Cells.Value("A1") = sName
End Sub





All times are GMT +1. The time now is 12:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com