Foo_Man_Chu
Board Regular
- Joined
- Jul 22, 2010
- Messages
- 79
I've written a small Sub that is really frustrating me. Sometimes it works just fine, other times I get the "Application-defined or object-defined error". I don't have any further information to give, sorry. I've thought about this one for quite a few hours now. For the sake of my sanity, please help me out......
Here's my code:
Here's my code:
Code:
Option Explicit
Public Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, Target.Worksheet.Range("C3")) Is Nothing Then
Dim WS As Worksheet
Dim LastCell As Range
Dim LastCellRowNumber As Long
Dim pc As PivotCache
Dim pt As PivotTable
Dim lastRow As String
Range("C3").Activate
If ActiveCell.Value <> vbNullString Then
Set WS = Worksheets("855_Template")
With WS
Set LastCell = .Cells(.Rows.Count, "C").End(xlUp)
LastCellRowNumber = LastCell.Row
End With
LastCell.Activate
lastRow = LastCell.Row
Dim quick As String
quick = "B2:H" & lastRow
Range(ActiveCell.Offset(0, -2), "A3").Select
Selection.Copy
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Dim blah As Worksheet
Set blah = ThisWorkbook.Worksheets("855_Summary")
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:="855_Template!" & quick, _
Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:=blah.Range("A1:D1"), TableName:="PTCtable69"
End If
End If
End Sub