Skip a Cell if Two Cells equal one another

maomao

New Member
Joined
Sep 5, 2017
Messages
6
I have this VBA, which is great, but in order to optimize it, I was wondering if there was a way to skip cells if two cells equal one another?

here is the code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Row = 248 And .Column > 7 And .Column < 556 Then
.Offset(-4).GoalSeek Goal:=.Value, ChangingCell:=.Offset(-5)
End If
End With
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It would be if

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If .Row = 248 And .Column > 7 And .Column < 40 were to equal .Offset(-4).
 
Upvote 0
Do you mean that if Target = Target.Offset(-4)?
 
Upvote 0
Try this then.
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    With Target
        If .Row = 248 And .Column > 7 And .Column < 556 Then
            If .Value = .Offset(-4).Value Then Exit Sub
            .Offset(-4).GoalSeek Goal:=.Value, ChangingCell:=.Offset(-5)
        End If
    End With

End Sub
[/code]
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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