I'm working on a stock management system with excel VBA. So far I've been able to add content to excel cells using a user form I created but I'm has trouble generating a random number for my stock id. Here is the sub routine I used. And I get true in the product I'd cell .
Sub random_random number()
For I = 100 to 999
Back:
Rand = Application.Roundup (rand () * 9000,0)
If Application. Countif(Range(B:B), Rand) > 0 then goto back
Else
Range ("B" & rows.count).end(xiup).offset (1,0).value = Rand
End if
Next
End sub
When I equate rand to the active cell which is the product ID cell. I get a TRUE instead of random of number.
Pls what an I doing wrong and how can I generated the random number without duplicated numbers
Sub random_random number()
For I = 100 to 999
Back:
Rand = Application.Roundup (rand () * 9000,0)
If Application. Countif(Range(B:B), Rand) > 0 then goto back
Else
Range ("B" & rows.count).end(xiup).offset (1,0).value = Rand
End if
Next
End sub
When I equate rand to the active cell which is the product ID cell. I get a TRUE instead of random of number.
Pls what an I doing wrong and how can I generated the random number without duplicated numbers