![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 3
|
I am making a spread sheet with questions that will have buttons such as strongly agree agree and disagree with a button for each answer. I want to total the number of times each button is pushed - how do I do this?
I know how to assign a macro to a button but don't know how to write the correct formula to get it to do the above - can anyone help? |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
try assigning these macros
Sub button1mac() Static button1 As Long button1 = button1 + 1 End Sub Sub button2mac() Static button2 As Long button2 = button1 + 1 End Sub where do you want the count to appear? This count will only last while the workbook is open. [ This Message was edited by: brettvba on 2002-04-16 17:22 ] |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
or try
Sub button1mac() Static button1 As Long button1 = Range("c11").Value button1 = button1 + 1 Range("c11").Value = button1 End Sub Sub button2mac() Static button2 As Long button2 = Range("d11").Value button2 = button2 + 1 Range("d11").Value = button2 End Sub where c11 has the value for button 1 and d11 has the value for button 2 when the workbook is saved the count will take off again from the current count |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Hi Brett,
Good one. Nice job. It might be even better to safeguard the value by assign the count to a defined name rather than a worksheet cell. That way, the user will have to delete or overwrite the name to mess up (don't worry, there's a 100% chance of somebody accidentally deleting the name just before it is needed most). Regards, Jay |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
|
quite right thanks
|
|
|
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
the user can't delete it except via code. ActiveWorkbook.Names.Add Name:=sCap & iIndex, RefersTo:=sNamedRef, Visible:=False |
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Ahmedabad Gujarat
Posts: 303
|
You can try this,,
Private Sub cmdcount_Click() Static intcount As Integer intcount = intcount + 1 cmdduplicate.Caption = "You have Pressed Button: " & intcount & " Times." End Sub nishith desai http://www.pexcel.com |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|