How to create a function to alternate names in a cell from a list?

E

Elias

Im creating a schedule and want to have a button that alternates names from a
list for the selected cell.
 
G

Gary''s Student

Here the list of name is in H1 thru H4:

Sub NextName()
Dim r1 As Range, r2 As Range
Set r1 = ActiveCell
Set r2 = Range("H1:H4")

If r1.Value = "" Then
r1.Value = r2(1).Value
Exit Sub
End If

v = r1.Value
For Each rr In r2
If rr.Value = v Then
Set r3 = rr.Offset(1, 0)
If Intersect(r3, r2) Is Nothing Then
Set r3 = r2(1)
End If
r1.Value = r3.Value
End If
Next
End Sub

Change the list to suit your needs.
Assign a button (or any piece of clipart) to the macro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top