Looping failed (From Excel to Ppt)

mmmarks

Active Member
Joined
Jun 4, 2011
Messages
432
Office Version
  1. 2013
Hi All,

I want to copy from Excel (Filtered Range) and paste in power point slide

Each copied Range in separate Slide . Like this I want to loop this action (Count is not fixed).

So far I've below code. which is not working as expected.
Code:
For Each Ccell In Worksheets("RAWDATA").Range("H2:H10")
    slidecount = myPresentation.slides.Count
    Set PPSlide = myPresentation.slides.Add(slidecount + 1, 12)
                   
   rcnt = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
   Set tbl = Worksheets("Sheet1").Range("A1:E" & rcnt)
 
   Worksheets("Sheet1").Activate
   Worksheets("Sheet1").Range("A1:E" & rcnt).AutoFilter
   tbl.AutoFilter 1, Criteria1:=Ccell
   
   tbl.SpecialCells(xlCellTypeVisible).Copy
  PPSlide.Shapes.PasteSpecial DataType:=2  '2 = ppPasteEnhancedMetafile
 
Next ccell
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
The following worked for me:


Code:
Sub XL_PPT()
Dim ccell As Range, objppt As Object, ppslide As Slide, tbl As Range, _
mypres As Presentation, ws As Worksheet
Set ws = Sheets("sheet1")
Set objppt = CreateObject("PowerPoint.Application")
objppt.Visible = True
objppt.Presentations.Open "c:\pub\2016\small1.pptx"
Set mypres = objppt.ActivePresentation
ws.Activate
Set tbl = ws.Range("A1:E" & ws.Range("A" & Rows.Count).End(xlUp).Row)
For Each ccell In Worksheets("RAWDATA").[H2:H4]
    Set ppslide = mypres.Slides.Add(mypres.Slides.Count + 1, 12)
    tbl.AutoFilter
    tbl.AutoFilter 1, Criteria1:=ccell
    tbl.SpecialCells(xlCellTypeVisible).Copy
    ppslide.Shapes.PasteSpecial DataType:=2
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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