ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   chose next page (https://www.excelbanter.com/excel-programming/368432-chose-next-page.html)

mike allen[_2_]

chose next page
 
this does work, but i would like to reduce it (as it gets much bigger than
even this):

sub test()
ActiveSheet.Next.Next.Next.Next.Next.Cells(1, 1) = "ok"
end sub

i want to choose the 5th sheet down from where i am now. i will not always
be on first sheet when running this, nor will i know the name of the 5th
sheet down.
i was thinking something like:
ActiveSheet.Next(5).Cells(1, 1) = "ok" (this does not work)
thanks, mike allen



Dave Peterson

chose next page
 
With no validation:

Option Explicit
Sub test()
Dim myIndex As Long
myIndex = ActiveSheet.Index
Sheets(myIndex + 5).Cells(1, 1).Value = "ok"
End Sub


mike allen wrote:

this does work, but i would like to reduce it (as it gets much bigger than
even this):

sub test()
ActiveSheet.Next.Next.Next.Next.Next.Cells(1, 1) = "ok"
end sub

i want to choose the 5th sheet down from where i am now. i will not always
be on first sheet when running this, nor will i know the name of the 5th
sheet down.
i was thinking something like:
ActiveSheet.Next(5).Cells(1, 1) = "ok" (this does not work)
thanks, mike allen


--

Dave Peterson


All times are GMT +1. The time now is 11:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com