Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
Command Button to store a value in Excel/VBA.......
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!!! -- chadtastic |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
Command Button to store a value in Excel/VBA.......
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 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!!! -- chadtastic |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how to create a command button, then assign macro to it in excel | Excel Discussion (Misc queries) | |||
Printing Access reports through Excel command button? | Excel Discussion (Misc queries) | |||
adding a command button to an excel cell? | Excel Discussion (Misc queries) | |||
command button in excel will move when print. | Excel Discussion (Misc queries) | |||
How do I setup a print command button in excel 2003 | New Users to Excel |