Hi all,
Apologies, I've been doing some reading and little out of my depth. I'm trying to convert the below code to work with worksheet_deactivate() command (when leaving a worksheet "Rebate Conditions"), however not having any luck. It works as a macro in a button on the sheet, just not when leaving the sheet so would assume is has to do with an activesheet issue.
I've read that the 1004 error will be caused by range issues in the code and tried adding in ME. and replacing activesheet with thisworkbook.sheets("rebate conditions") with no success.
Hoping someone may be able to steer me right.
G2 is a fixed value. H2 is a variable.
Apologies, I've been doing some reading and little out of my depth. I'm trying to convert the below code to work with worksheet_deactivate() command (when leaving a worksheet "Rebate Conditions"), however not having any luck. It works as a macro in a button on the sheet, just not when leaving the sheet so would assume is has to do with an activesheet issue.
I've read that the 1004 error will be caused by range issues in the code and tried adding in ME. and replacing activesheet with thisworkbook.sheets("rebate conditions") with no success.
Hoping someone may be able to steer me right.
Code:
Sub Refresh_Rebates()Dim RCount As Integer
'Optimize Code
Call OptimizeCode_Begin
Rows.EntireRow.Hidden = False
RCount = Range("D" & ActiveSheet.Rows.Count).End(xlUp).Row
Range("B4:R" & RCount).Sort key1:=Range("E5:E" & RCount), Order1:=xlDescending, Header:=xlYes
Range("G2").Select
Selection.Copy
Range("H2").Select
ActiveSheet.Paste
Rows.EntireRow.Hidden = False
RCount = Range("B" & ActiveSheet.Rows.Count).End(xlUp).Row
For i = 5 To RCount
If Range("D" & i).Value = 0 Then
Range("J" & i).Value = ""
Range("M" & i).Value = ""
Range("P" & i).Value = ""
End If
Next
'Optimize Code
Call OptimizeCode_End
MsgBox "Data updated"
End Sub