New to Visual Basic

  • Thread starter Need help with sumif
  • Start date
N

Need help with sumif

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
 
B

Bob Phillips

You add a button to the worksheet and call it CommandButton1. Then you click
it.
 
M

Mike H

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
 
L

Luke M

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top