Intersect(ActiveCell) Combining Ranges and Target.Value

kivikatz

New Member
Joined
Sep 12, 2020
Messages
25
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi All. Is it possible to combine the following two If Not Intersect statements into one statement? What I want to do is when I click on a cell in column B (1st If Not Intersect), it also activates the corresponding cell in column N (2nd If Not Intersect). For example, if click on B50 (which is inserted into "Symbol"), it will also activate N50 (which is inserted into "DateInput").

Hope you understand what I am trying to do. Thanks.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(ActiveCell, Range("B10:B110")) Is Nothing Then
Sheet311.Range("Symbol") = Target.Value
End If

If Not Intersect(ActiveCell, Range("N10:N110")) Is Nothing Then
Sheet311.Range("DateInput") = Target.Value - 1
End If

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Just have the first IF block select the same row in column N, which will trigger the code to run again, i.e.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.CountLarge > 1 Then Exit Sub

If Not Intersect(Target, Range("B10:B110")) Is Nothing Then
    Sheet311.Range("Symbol") = Target.Value
    Cells(Target.Row, "N").Select
End If

If Not Intersect(Target, Range("N10:N110")) Is Nothing Then
    Sheet311.Range("DateInput") = Target.Value - 1
End If

End Sub
Also note. Typically in these kind of event procedures, you do not use ActiveCell, but rather use Target (which is the cell that is selected that activates the code to run).
 
Upvote 0
Solution
You are weclome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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