I have a excelsheet with loads of data that is filtered, sorted och then two ranges are combined using union. Thesee ranges, a header and chart is the copied to a ppt.
After this is done the script should look fot the next part of the table and union then puts the main categories with the new content together in a range and is pasted to a ppt with the new header and a new graph.
Everything works fine except that for some reason, the range that I pass to the ppt does not only take the new range, it takes the new with the old one and pastes it into the ppt.
When I use the immidiate window and just paste the range into a blank excel it looks right. But for some reason it does not takes the old and new range. For every loop this range just gets larger and larger.
Can someone tell me what I'm doing wrong?
A part of my code:
'Add the header and the cars
Set pptHeader = Range(Cells(1, 2), Cells(3, lastCarColumn))
'Content to follow with the header
'Set pptContent = Range(Cells(4, 2), Cells(5, lastCarColumn))
Set pptContent = Range(Cells(topRangeRow, 2), Cells(bottomRangeRow, lastCarColumn))
'Combining the ranges
Set pptTotal = Union(pptHeader, pptContent) '.Select
pptTotal.SpecialCells(xlCellTypeVisible).Copy
'Getting the content header and compare to the Chart Title
Dim oChart As ChartObject
Dim oCharts As ChartObjects
Dim header, slideHeader As String
Dim headerRow As Integer
'Get the content header
headerRow = pptContent.Rows.Count
header = pptContent(pptContent.Rows.Count, 1).Value
'Loops through all charts in the Chart sheet and looks for the right header
For Each oChart In sht3.ChartObjects
oChart.Activate
If oChart.chart.HasTitle Then
If activeChart.ChartTitle.Text = header Then
slideHeader = activeChart.ChartTitle.Text
Debug.Print slideHeader
Exit For
End If
End If
Next oChart
'Calls function/sub that copy/pastes the content to the ppt
excelRangeToPpt (pptTotal)
'Calls function to set slide Chart
setSlideChart
'Calls function to set slide header title
excelTitleToPpt (slideHeader)
'Resetting
Application.CutCopyMode = False
Set pptHeader = Nothing
Set pptContent = Nothing
Set pptTotal = Nothing
sht1.Activate
ActiveCell.Offset(1, 0).Activate
Application.ScreenUpdating = True
Bookmarks