|
-
Jul 14th, 2004, 10:19 PM
#1
Thread Starter
New Member
Excel IF statement in macros
Hello all,
My Excel sheet is generating random numbers from 1 to 10 using the randbetween function. I am trying to write a macro to keep a count of how many of each number there are and display those numbers on the sheet as the random number is created.
To create each random number I have a button attached to a macro which just has the instruction calculate. This works fine.
After the calculate instruction I have added some code that I thought should keep a count and display each count on the sheet:
IF range("H14") = 1 then
range ("B2") = range ("B2") +1
END IF
and then another similar 9 of these if H14 has a value of 2 or 3 etc
(H14 is the cell that contains the random numbers and B2, C2 etc are where I want to display the count results).
When I activate the macro by clicking on my button the new random number is generated but I get counts increasing in other cells as well as the targeted one. ie if the random number is a 5, my count for the number 7 may increase by 1.
Questions
1. Is this the simplest way to keep a count of each random number?
2. What's wrong with the macro?
Any help appreciated,
DCD
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|