Variable Array based on cell value

Eddanon

New Member
Joined
Jun 19, 2015
Messages
11
Hello, everybody.
The following code shows an array with fixed size, with 6 values. What should i do to make its size depends on a cell value? For example, from 1 to 10?




Code:
 Dim MySlideArray As Variant
         Dim MyRangeArray As Variant
[INDENT] 'List of PPT Slides to Paste to[/INDENT]
[INDENT]   MySlideArray = Array(2, 3, 4, 5, 6, 7)[/INDENT]
[INDENT] [/INDENT]
[INDENT] 'List of Excel Ranges to Copy from. For now, assume that it's always 5 ranges[/INDENT]
[INDENT]  With tb.DataBodyRange[/INDENT]
[INDENT]     MyRangeArray = Array(Worksheets(.Cells(1, 1).Value).Range(.Cells(1, 2).Value), _[/INDENT]
[INDENT]                    Worksheets(.Cells(2, 1).Value).Range(.Cells(2, 2).Value), _[/INDENT]
[INDENT]                    Worksheets(.Cells(3, 1).Value).Range(.Cells(3, 2).Value), _[/INDENT]
[INDENT]                    Worksheets(.Cells(4, 1).Value).Range(.Cells(4, 2).Value), _[/INDENT]
[INDENT]                    Worksheets(.Cells(5, 1).Value).Range(.Cells(5, 2).Value), _[/INDENT]
[INDENT]                    Worksheets(.Cells(6, 1).Value).Range(.Cells(6, 2).Value))


'Loop through Array data
  For x = LBound(MySlideArray) To UBound(MySlideArray)
    'Copy Excel Range
        MyRangeArray(x).Copy
    
    'Paste to PowerPoint and position
      On Error Resume Next
        Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) 'Excel 2007-2010
        Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
      On Error GoTo 0
[/INDENT]
 
Thanks for your answer! i got help from a friend and it worked!
Here is the solution:
Code:
Dim MyRangeArray As Variant 
Dim x As Long 
Dim tb As ListObject 
Dim c As Range 
Dim osld As Slide 
Dim I As Integer 
Dim z As Integer 
Dim n As Long 
 
Set tb = Worksheets("Home").ListObjects("tblCopy") 
With tb.DataBodyRange 
    ReDim MyRangeArray(.Rows.Count - 1) 
    For n = 1 To .Rows.Count 
       Set MyRangeArray(n - 1) = Worksheets(.Cells(n, 1).Value).Range(.Cells(n, 2).Value) 
    Next 
End With 
(...) 
 
For x = LBound(MyRangeArray) To UBound(MyRangeArray) 
     [COLOR=darkgreen]'Copy Excel Range[/COLOR]
    MyRangeArray(x).Copy 
     
     [COLOR=darkgreen]'Paste to PowerPoint and position[/COLOR]
    On Error Resume Next 
    Set shp = myPresentation.Slides(x + 2).Shapes.PasteSpecial(DataType:=2) [COLOR=darkgreen]'Excel 2007-2010[/COLOR]
    Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange [COLOR=darkgreen]'Excel 2013[/COLOR]
    On Error GoTo 0
What exactly do you have in the table?

Can you post some sample data?
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top