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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,281
Office Version
  1. 365
Platform
  1. Windows
Which 2 cells?
 

maomao

New Member
Joined
Sep 5, 2017
Messages
6
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).
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,281
Office Version
  1. 365
Platform
  1. Windows
Do you mean that if Target = Target.Offset(-4)?
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,281
Office Version
  1. 365
Platform
  1. Windows
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]
 

Watch MrExcel Video

Forum statistics

Threads
1,129,579
Messages
5,637,208
Members
416,960
Latest member
Carbon1198

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
Top