tchakravarty
tchakravarty

Reputation: 10984

Random Numbers in PowerPoint Table using VBA

I would like to populate all of the selected cells in a PowerPoint table with randomly generated numbers using PowerPoint VBA.

I am able to insert a randomly generated number at the current cursor position using this sub-routine:

Sub RandomNumberGenerator()
    Dim oRange As TextRange
    Set oRange = ActiveWindow.Section.TextRange.Characters
    oRange.Text = Int(Rnd()*10000)
End Sub 

How can I extend it to fill in random numbers in all selected cells of a Table?

Upvotes: 0

Views: 358

Answers (1)

Jamie Garroch - MVP
Jamie Garroch - MVP

Reputation: 2999

You need to first determine that the selection shape range includes a table and then loop through the rows and columns, checking to see if each cell is selected and if it is, insert your random number text into the cell's corresponding shape object.

Upvotes: 0

Related Questions