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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,214,561
Messages
6,120,242
Members
448,951
Latest member
jennlynn

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