MOD Func

ExcelChampion

Well-known Member
Joined
Aug 12, 2005
Messages
976
The below is simple:

If I type 3 in A1 the formula returns 1. If I type 1 in A1 the formula returns 2. If I type 2 in A1 the formula returns 3.

I want the opposite. If I type 2 in A1 it returns 1. If I type 1 in A1 it returns 3. If I type 3 in A1 it retunrs 2.

Can't get my head around it. Any help is appreciated.
PPT.xls
ABCD
13
2
31
Sheet1
 
Todd

Couldn't you use something like this?
Code:
Sub sht_Forward()
      If ActiveSheet.Index = Sheets.Count Then
            Application.Goto Sheets(1).Range("A1"), True
      Else
            Application.Goto Sheets(ActiveSheet.Index+1).Range("A1"), True
      End If
End Sub

Absolutely I could. but, this just seemed cleaner to me. Just call me picky.

Code:
Sub sht_Forward() 
    Sheets(Evaluate("MOD(" & ActiveSheet.Index& "," & Worksheets.Count & ")+1")).Select 
End Sub
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Todd

If that works that's the important thing.:)

But I would have to ask why are you using Evaluate?

Why not actually use the VBA Mod function?
Code:
Sub sht_Forward()
    
    Application.Goto Sheets(ActiveSheet.Index Mod Sheets.Count + 1).Range("A1"), True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,011
Members
449,204
Latest member
tungnmqn90

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