Worksheet selection change formula entry

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,007
Office Version
  1. 365
Platform
  1. Windows
I am trying to enter the following formula into cells on a worksheet change event but it errors out.

formula to input is: "=IF(H$10="",($H$8/12*K$8),($H$8/12*K$8)+H$10)"

I have used the following format to do this:

Code:
   Case "Post Tender Activity"
            .Range("J4:M4,o4:r4").Formula = "=0"
            Target.Offset(0, 12).Formula = "=IF(H$10="",($H$8/12*K$8),($H$8/12*K$8)+H$10)"
            Target.Offset(0, 13).Formula = "=IF(I$10="",($H$8/12*L$8),($H$8/12*L$8)+I$10)"

when selecting "Post Tender Activity", the first line clears the range preceding the cells where the formula is to reside, and then it errors out on the line beginning Target.Offset(0,12) with the message "Application defined or Object defined error".

If i change out the formula bit to simply activate the cell, it works a treat.
 
smitty, the sheet change is causing problems.

can you see anything wrong with what i have here:

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

'///shifts savings depending on Status - Est>Target>Banked and back again.

    Dim shtFirst%, shtLast%
    shtFirst = Worksheets("First").Index
    shtLast = Worksheets("Last").Index
    If ActiveSheet.Index <= shtFirst Then Exit Sub
    If ActiveSheet.Index >= shtLast Then Exit Sub
    If Target.Cells.Count > 1 Then Exit Sub
    If Intersect(Target, Range("$I$4")) Is Nothing Then Exit Sub

    With Application
        .ScreenUpdating = False
        '.Unprotect
        Select Case Target.Value

        Case "Preparation"
            With Sh
                .Range("$D$4").Value = 1
                .Range("$J$4:$M$4,$T$4:$W$4").Value = 0
                .Range("$P$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$Q$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        Case "RFx"
            With Sh
                .Range("$D$4").Value = 1
                .Range("$J$4:$M$4,$T$4:$W$4").Value = 0
                .Range("$P$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$Q$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        Case "Negotiate"
            With Sh
                .Range("$D$4").Value = 1
                .Range("$J$4:$M$4,$T$4:$W$4").Value = 0
                .Range("$P$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$Q$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        Case "Approval"
            With Sh
                .Range("$D$4").Value = 1
                .Range("$J$4:$M$4,$T$4:$W$4").Value = 0
                .Range("$P$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$Q$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        Case "Completed"
            With Sh
                .Range("$D$4").Value = 1
                .Range("$J$4:$M$4,$O$4:$R$4").Value = 0
                .Range("$U$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$V$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        Case "Savings Validation"
            With Sh
                .Range("$D$4").Value = 1
                .Range("$J$4:$M$4,$O$4:$R4$").Value = 0
                .Range("$U$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$V$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        Case "Closed"
            With Sh
                .Range("$D$4").Value = 0
                .Range("$J$4:$M$4,$O$4:$R$4,$T$4:$W$4").Value = 0
            End With

        Case "On Hold"
            With Sh
                .Range("$J$4:$M$4,$T$4:$W$4").Value = 0
                .Range("$P$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$Q$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        Case "Not Started"
            With Sh
                .Range("$D$4").Value = 3
                .Range("$O$4:$R$4,$T$4:$W$4").Value = 0
                .Range("$K$4").Formula = "=IF($G$8=0,0,IF($H$10="""",($H$8/12*$K$8),($H$8/12*$K$8)+$H$10))"
                .Range("$L$4").Formula = "=IF($G$8=0,0,IF($I$10="""",($H$8/12*$L$8),($H$8/12*$L$8)+$I$10))"
            End With

        End Select
        .Calculate
        '.Protect
        .ScreenUpdating = True
    End With
End Sub

i get the method intersect error now each time i try to close.
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

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