Find the last matching activecell value in cells below and then select.

danbates

Active Member
Joined
Oct 8, 2017
Messages
357
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have a code that would already select the first D or N depending on what shift it is at work.
I would like a code that can then find the last cell value that matches the activecell value in column B but searches from the activecell downwards.

Example:
D
N
D
N - This is the activecell
N
N
N - I would like a code that would select this row in column B instead.
D
N
D

Any help would be appreciated.

Thanks
Dan
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,235
Office Version
  1. 2016
Platform
  1. Windows
Why select that cell? There is a cell further down which contains N.
 

danbates

Active Member
Joined
Oct 8, 2017
Messages
357
Office Version
  1. 2016
Platform
  1. Windows
Hi,
I need it to be that cell because it is on the same shift as the first D or N of that block of D's or N's.

The last N of my example would be the following night shift.
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,235
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Sub v()
Dim c As Range: Set c = ActiveCell
Dim i&: i = 2
Do While c(i) = c.Value
    i = i + 1
Loop
c(i - 1).Select
End Sub
 
Solution

danbates

Active Member
Joined
Oct 8, 2017
Messages
357
Office Version
  1. 2016
Platform
  1. Windows
Perfect, just what I wanted.

Thank you footoo
 

Watch MrExcel Video

Forum statistics

Threads
1,130,154
Messages
5,640,438
Members
417,142
Latest member
andygame

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