Rolling List in Excel

Craig13_13

New Member
Joined
Apr 9, 2009
Messages
21
Hi there

I'm sure it's a nice simple piece of code but I can't find it! I have a list of names on a sheet and am trying to make it a rolling rota, i.e. there is a name in a cell, you click a button and the name in the cell changes to the next name in the list, and when it gets to the bottom of the list it goes back to the top and works it's way down again, can anyone offer any help please?

Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Assuming ...
- the list is in column A, starting in row 2
- the 'rolling' list is to appear in cell C1
... then try this code for yout button.

<font face=Courier New><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br>    <SPAN style="color:#00007F">Dim</SPAN> lr <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, r <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br>    <SPAN style="color:#00007F">Dim</SPAN> myval<br>    <SPAN style="color:#00007F">Dim</SPAN> myTarget <SPAN style="color:#00007F">As</SPAN> Range<br>    <br>    lr = Range("A" & Rows.Count).End(xlUp).Row<br>    <SPAN style="color:#00007F">Set</SPAN> myTarget = Range("C1")<br>    myval = myTarget.Value<br>    <SPAN style="color:#00007F">If</SPAN> myval = "" <SPAN style="color:#00007F">Then</SPAN><br>        myTarget.Value = Range("A2").Value<br>    <SPAN style="color:#00007F">Else</SPAN><br>        r = Range("A2:A" & lr).Find(What:=myval, LookIn:=xlValues, _<br>            Lookat:=xlWhole, MatchCase:=False, SearchFormat:=False).Row<br>        <SPAN style="color:#00007F">If</SPAN> r = lr <SPAN style="color:#00007F">Then</SPAN><br>            myTarget.Value = Range("A2").Value<br>        <SPAN style="color:#00007F">Else</SPAN><br>            myTarget.Value = Range("A" & r + 1).Value<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
My effort:

Code:
Sub test()
Dim findRange As Range
With Range("C1")
If .Value = "" Then
    .Value = Range("A1")
    
Else
    Set findRange = Range("A1:A10").Find(.Value, LookIn:=xlValues)
    
    If Not findRange Is Nothing Then
    
        If findRange.Offset(1, 0) = "" Then
        
            .Value = Range("A1")
            
        Else
        
            .Value = findRange.Offset(1, 0)
            
        End If
        
    End If
End If
End With
End Sub

Loops through the list in A1:A10 putting the value in C1.

Dom
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,804
Members
452,943
Latest member
Newbie4296

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