Consulting

Results 1 to 4 of 4

Thread: Create random slide number (2 to x) and keep the same throughout the show.

  1. #1

    Create random slide number (2 to x) and keep the same throughout the show.

    I want to generate a random number from 4 to x, (x being the number of slides in the show) on the first slide and keep that variable unchanged throughtout thewhole show.

    In a previous post I dont think i explained it right and presented code that was full of errors. I can generate the numbers but cannot keep them throughout the slideshow.

    Windows 10 Home
    Powerpoint 19

    Any advise or solution would be greatly appreciated.

    Fred

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,939
    Location
    Try this Note you said 2 - x and 4-x change low_range to suit

    Dim lngRand As Long ' declare outside sub
    
    Sub makernd()
    Dim high_range As Long
    Dim low_range As Long
    low_range = 2
    high_range = ActivePresentation.Slides.Count
    Randomize
    lngRand = Int((high_range - (low_range - 1)) * Rnd) + low_range
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,939
    Location
    Try this Note you said 2 - x and 4-x change low_range to suit

    Dim lngRand As Long ' declare outside sub
    
    Sub makernd()
    Dim high_range As Long
    Dim low_range As Long
    low_range = 2
    high_range = ActivePresentation.Slides.Count
    Randomize
    lngRand = Int((high_range - (low_range - 1)) * Rnd) + low_range
    End Sub
    Sorry posted twice slip of finger!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    Thank you John. I remained with my code, but used your dim outside the sub and got my desired results. I had thought I tried that before but this time it worked!!! THANK YOU!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •