Hello!
I'm attempting to add names within a small cell range (6 cells) by using a button attached to a particular name (21 buttons attached to unique names). Using the below code, I'm able to add the names within that range, but a name is not always added with a single button press (because of the Rnd function maybe?). In other words, sometimes I have to hit the button several times for the name to show up.
I'd like to fix the issue of the button not ALWAYS adding a name (unless the cell has existing data), but it would be nice if the names were added sequentially within the defined range (i.e. clicking the button starts with N2 and moves to the next if there is data already present).
Either way, thanks for the help, and sorry if this was brought up elsewhere.
I'm attempting to add names within a small cell range (6 cells) by using a button attached to a particular name (21 buttons attached to unique names). Using the below code, I'm able to add the names within that range, but a name is not always added with a single button press (because of the Rnd function maybe?). In other words, sometimes I have to hit the button several times for the name to show up.
Code:
Sub add_1()
Dim rCells As Range
Set rCells = Range("N2:S2")
Dim rRandom As Long
rRandom = Int(Rnd * rCells.Cells.Count) + 1
With rCells.Cells(rRandom)
If IsEmpty(rCells.Cells(rRandom)) Then
.Value = "Bastion"
End If
End With
End Sub
I'd like to fix the issue of the button not ALWAYS adding a name (unless the cell has existing data), but it would be nice if the names were added sequentially within the defined range (i.e. clicking the button starts with N2 and moves to the next if there is data already present).
Either way, thanks for the help, and sorry if this was brought up elsewhere.