Worksheet Change Event Firing Outside of Range

Nadine

New Member
Joined
May 12, 2020
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Hello and thank you for any attention my post may receive

I have modified the code below (which was given to me through a previous post) to suit my current project.....without success.

The code is doing/not doing a couple of things.
1. returning 'Run-time error 424 - Object required' whenever I update a cell outside of the target range.
2. not firing when I update a cell within the target range.

Debug is pointing to the 'red' text line of code below.
The value in '.Offset(0, -6)' is a formula calculated value.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Dim Cell As Range
    Set rng = Intersect(Target, Range("H:H"))
    [COLOR=rgb(184, 49, 47)][B]For Each Cell In rng[/B][/COLOR]
        If Not IsEmpty(Cell) And Not IsEmpty(Cell.Offset(1, 0)) Then
            With Cell
                If .Offset(0, -6).Value = 1 Then
                    With .Resize(1, 18).Offset(0, -6).Borders(xlEdgeTop)
                        .linestyle = xlContinuous
                        .Weight = xlMedium
                        .ColorIndex = xlAutomatic
                    End With
                End If
            End With
        End If
    Next Cell
End Sub

Thank you!
 
The first response will only work when one cell only is changed (in column H).
The code I posted allows for more than one cell in column H to be changed (as in copy/paste, dragging, Ctrl+Enter, etc.), which in line with your original code.
Oh I see. I shall revisit my workbook and change it.

Thank you very much for pointing that out to me.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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