Create Next and Previous Buttons on Userform

  • Thread starter Thread starter nrage21
  • Start date Start date
N

nrage21

Hi guys,
Thx a lot for all your help over the past months!!

I have an userform, and I would like to create 2 commandbuttons tha
will allow the user to move from one worksheet to the next and th
other to move from one worksheet to the previous and when the last o
first worksheet is reached to keep going in circles.

i.e. if user reaches last worksheet and clicks Next to go back to firs
worksheet.

I have a total of 9 worksheets, is that is important.

This is probably the easiest problem to solve, I'm sure.

- Larry -
VBA Amateu
 
if activeSheet.Index = Sheets.count then
Sheets(1).Activate
else
sheets.Next.Activate
End if


if activeSheet.Index = 1 then
Sheets(Sheets.count).Activate
else
sheets.Previous.Activate
End if
 
Hi nrage21,
I have an userform, and I would like to create 2 commandbuttons that
will allow the user to move from one worksheet to the next and the
other to move from one worksheet to the previous and when the last or
first worksheet is reached to keep going in circles.

i.e. if user reaches last worksheet and clicks Next to go back to
first worksheet.

Something like this should work:

Private Sub cmdPrevious_Click()
If ActiveSheet.Index = 1 Then
Sheets(Sheets.Count).Activate
Else
Sheets(ActiveSheet.Index - 1).Activate
End If
End Sub

Private Sub cmdNext_Click()
If ActiveSheet.Index = Sheets.Count Then
Sheets(1).Activate
Else
Sheets(ActiveSheet.Index + 1).Activate
End If
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]
 
Thanks for the quick replies guys!

(Tom: now I can put the comments to a face... I saw a picture of yo
and Chip in Chip Pearson Site... "gentle faces")

:)


- Larry -
VBA Amateu
 

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

Back
Top