Home > OS >  How to create a vba which selects a random amount of character within a given limit?
How to create a vba which selects a random amount of character within a given limit?

Time:10-20

This is the simplest way to select the specific number of character

Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend

I'm having a problem with incorporating the random function.

Thank you for the help in advance.

CodePudding user response:

Try this way, please:

Sub extendSelRndCharacters()
   Dim iMin As Long, iMax As Long, nrCount As Long
   iMax = 5: iMin = 1 'limits for number of characters to be operated
   Randomize
   nrCount = Int((iMax - iMin   1) * Rnd   iMin)
   Selection.MoveRight Unit:=wdCharacter, Count:=nrCount, Extend:=wdExtend
End Sub
  •  Tags:  
  • vba
  • Related