Random number generation

Awiniki

New Member
Joined
Feb 22, 2018
Messages
1
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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
generate a list of random numbers
put 1 to 100 in A1 to A100
put in a random number in B1 to B100 using =rand()
copy col b
edit paste special values
sort by col B ascending
delete column B
you now have the numbers 1 to 100 randomly shuffled
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,086
Members
448,944
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top