Forum Discussion
jim johnstone
Feb 13, 2018Copper Contributor
Random alphanumeric generation in a cell
Hi everyone.
A bit of a newbie when it comes to Excel here.
What I'm trying to achieve is a means of automatically generating an alphanumeric string, lets say 7 long, when clicking on a cell....
jim johnstone
Feb 13, 2018Copper Contributor
That's brilliant sir, you're a star!
Now, is there a way to have it generate a number into C8 and ONLY if the field is empty in C8 to prevent new numbers being generated when the field has a value?
After that, I should be able to copy that data into subsequent fields
Anonymous
Feb 14, 2018'Shorter Range("C8") version
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = Me.Range("C8").Address Then
If VBA.Len(Target.Value) < 1 Then
Randomize
Target.Value2 = VBA.Int((9999999 - 1000001 + 1) * Rnd + 1000001)
End If
Cancel = True
End If
End Sub
- jim johnstoneFeb 14, 2018Copper Contributor
Thanks again-that's perfect.
Kindest regards,
Jim