vba - search right to left for first non-matching value

MisterProzilla

Active Member
Joined
Nov 12, 2015
Messages
264
Hi there,

What I'm trying to achieve seems pretty simple, just can't figure out the syntax.

On a single row, I enter blocks of numbers which represent sessions, in increments of 15 mins per cell. For example, I might have a number 1 in all cells D2:K2, representing a 2-hour long session.
I want to be able to click on a session, click a button and have the start time and end time retrieved for me in VBA. To do this, I think the easiest way would be to search left, from the active cell, for the first cell that isn't a '1', and return the column; then search right for the first non-'1' cell and return the column. From there, I can offset those column numbers to look up the start/end times along the top.

I'm just stuck on how to look for a value that is not 1 (or whatever is in the active cell, which I can find with ActiveCell.Value)

This is as far as I've got with the code:

Code:
Sub find()


Dim findstart As Long
Dim findend as long


findstart = Sheet4.Range(Cells(2,4),Cells(2,ActiveCell.Column)).Find([B]???[/B], searchdirection:=xlPrevious).Column
findend = Sheet4.Range(Cells(2,ActiveCell.Column),Cells(2,48)).Find([B]???[/B], searchdirection:=xlNext).Column

'look for times in those offset columns, etc



End Sub

Where I've entered ??? is where I need to have it look for a value that doesn't match that of the active cell.
Seems like this should be an easy one, just getting lost in translation from head to VBA :)

Thanks for looking
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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