Command Button to store a value in Excel/VBA.......

C

chadtastic

Hi,

All I need is to know how to use a command button in vba to store a
value in a cell in Excel.

I have a user form with two command buttons on it. one button is
labeled, "Test1", the other labeled, "Test2."

When the user clicks on the button labeled, "Test1", I want the word,
"Test1" to appear in the next available cell in row, "A." When the
user clicks onk, "Test2", I want the word, "Test2" to appear in the
next available cell in row, "A."

I want it set up so that every time the user clicks on either button,
it stores the value in the next available row without replacing the
exiisting value that is in the cell. So say the user clicks on the,
"Test1CommandButton", it stores, "Test1" in, "A1." And the next time
they click the, "Test1(or Test2)CommandButton", it stores, "Test1"(or,
"Test2"), in, "A2", ect..........Thats it.

I'm guessing the code is something like the following.......

Test1CommandButton Click()
Sheet("Sheet1").Range("A" & NextRow) = ("Test1").......??? <--something
like this?

Test2CommandButton Click()
Sheet("Sheet1".Range("A" & NextRow) = ("Test2").......??? <----again,
something like this?

I know how to store the value with an InputBox but not with a command
button and I would rather use the command button in this particular
case.

Any help would be greatly appreciated, thank you!!!
 
G

Guest

Try

Private Sub CommandButton1_Click()
NextRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Sheet1").Range("A" & NextRow) = "Test1"

End Sub"chadtastic" wrote:

Right click on command button and "view code
 

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