Jurij
07-02-2014, 10:03 AM
Hi guys,
I am trying to do a simple thing - delete the rows that were copied into a spreadsheet after VBA has copied them into Powerpoint tables. Here is the code, it is run from PowerPoint (I left out the PowerPoint code since that one works normally):
Sub delete_rows()
Dim OWB As Excel.Workbook
Set OWB = GetObject("C:\readout\matrix.xlsx ")
Dim WS1 As Excel.Worksheet
Set WS1 = OWB.Worksheets(1)
Dim WS2 As Excel.Worksheet
Set WS2 = OWB.Worksheets(2)
WS1.AutoFilter.Range.Copy
WS2.Select
WS2.Range("A2").Select
OWB.ActiveSheet.Paste
WS2.Range("A3:A" & Range("A3").End(xlDown).Row).EntireRow.Delete
End Sub
The code that doesnīt work is "WS2.Range("A3:A" & Range("A3").End(xlDown).Row).EntireRow.Delete". It works normally when executed in an excel spreadsheet, but here I keep getting "Method "Range" of object "_Global" failed". Any suggestions on how to bypass this are welcomed.
Additionally, just out of curiosity:
"WS2.Range("A2").Select" didnīt work without "WS2.Select" befor it. Any ideas why that is the case?
Thank you,
Jurij
I am trying to do a simple thing - delete the rows that were copied into a spreadsheet after VBA has copied them into Powerpoint tables. Here is the code, it is run from PowerPoint (I left out the PowerPoint code since that one works normally):
Sub delete_rows()
Dim OWB As Excel.Workbook
Set OWB = GetObject("C:\readout\matrix.xlsx ")
Dim WS1 As Excel.Worksheet
Set WS1 = OWB.Worksheets(1)
Dim WS2 As Excel.Worksheet
Set WS2 = OWB.Worksheets(2)
WS1.AutoFilter.Range.Copy
WS2.Select
WS2.Range("A2").Select
OWB.ActiveSheet.Paste
WS2.Range("A3:A" & Range("A3").End(xlDown).Row).EntireRow.Delete
End Sub
The code that doesnīt work is "WS2.Range("A3:A" & Range("A3").End(xlDown).Row).EntireRow.Delete". It works normally when executed in an excel spreadsheet, but here I keep getting "Method "Range" of object "_Global" failed". Any suggestions on how to bypass this are welcomed.
Additionally, just out of curiosity:
"WS2.Range("A2").Select" didnīt work without "WS2.Select" befor it. Any ideas why that is the case?
Thank you,
Jurij