What is wrong with this line in my code?

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,750
Hi all,

Below is my code and it was running perfectly until I added the bolded underlined line below:

Rich (BB code):
Private Sub worksheet_change(ByVal target As Range)

Dim TRowNum As Integer
Dim LDTask As Integer
Dim PRange As Range
Dim lRow1 As Integer

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False

If Not Intersect(target, Columns("b")) Is Nothing Then

  If UCase(target.Value) = "OK" And target.Offset(0, -1).Value <> 0 Then

  TRowNum = target.Row
  LDTask = Sheets("List - Completed tasks").Range("A65536").End(xlUp).Row + 1


     With Sheets("List - Completed tasks")
       .Unprotect Password:="der"
       
        Sheets("List - Pending tasks").Rows(TRowNum).Copy
       
       .Range("A" & LDTask).PasteSpecial Paste:=xlPasteValues
       .Range("C" & LDTask).Value = Date
       .Range("D" & LDTask).Value = Time()
       .Protect Password:="der"
     End With

  Sheets("List - Pending tasks").Activate
  Rows(TRowNum).Delete
  
     With Sheets("Pivot - Completed tasks")
       .Unprotect Password:="der"
       .PivotTables("PivotTable1").PivotCache.Refresh
        lRow1 = .Range("B65536").End(xlUp).Row
       .Range("A5:E5").Copy
       .Range("A6:E" & lRow1).PasteSpecial Paste:=xlPasteFormats
       .Range("A4").Select       
       .Protect Password:="der"
     End With
  
  End If


End If

Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

I could of course just take the line out but the point is I want to know why is this a debug error?

Thanks in advance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
The Range(??).Select method can only select a cell\range on the active sheet.

You have Sheets("List - Pending tasks") as the active sheet and you are trying to select Sheets("Pivot - Completed tasks").Range("A4").Select
 
Upvote 0
The Range(??).Select method can only select a cell\range on the active sheet.

You have Sheets("List - Pending tasks") as the active sheet and you are trying to select Sheets("Pivot - Completed tasks").Range("A4").Select

Thanks Alfrafrog. I didn't know that.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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