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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
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,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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