ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Locate Value in a set Row, with Dynamic Column (https://www.excelbanter.com/excel-programming/436970-locate-value-set-row-dynamic-column.html)

Louise

Locate Value in a set Row, with Dynamic Column
 
Hi,

I have some data and the headers for the numbers are months. All the months
are on row 7. I need to add some code to start looking in row 7 (cell A7)
and look at each column to locate the relevant date entered in cell A1.

Example: The code needs to look at cell A7, then B7, then C7 etc etc until
it locates the right value.

How can I do this please?

Thanks,

Paul W Smith

Locate Value in a set Row, with Dynamic Column
 
What do you want thew code to do when it finds the match?


"Louise" wrote in message
...
Hi,

I have some data and the headers for the numbers are months. All the
months
are on row 7. I need to add some code to start looking in row 7 (cell A7)
and look at each column to locate the relevant date entered in cell A1.

Example: The code needs to look at cell A7, then B7, then C7 etc etc until
it locates the right value.

How can I do this please?

Thanks,




Louise

Locate Value in a set Row, with Dynamic Column
 
Actually I worked it out - Thanks anyway..

Range("B7").Select
Do
If ActiveCell < nowmonth Then
ActiveCell.Offset(0, 1).Select
End If
Loop Until ActiveCell = nowmonth

ActiveCell.Offset(1, 0).Select


:)


"Louise" wrote:

Hi,

I have some data and the headers for the numbers are months. All the months
are on row 7. I need to add some code to start looking in row 7 (cell A7)
and look at each column to locate the relevant date entered in cell A1.

Example: The code needs to look at cell A7, then B7, then C7 etc etc until
it locates the right value.

How can I do this please?

Thanks,


Rick Rothstein

Locate Value in a set Row, with Dynamic Column
 
If I understand what you want correctly (A1 contains a **real** Excel date
whose month you want to find in Row 7 where A7 contains January, B7 contains
February, etc.), then this single line of code should do what your 7 lines
of code do...

Cells(7, Month(Range("A1").Value)).Offset(1).Select

By the way, the code you posted starts looking from B7, but your original
message seemed to indicate that January was in A7... your code, as written,
will not find a January date... you would need to change your B7 to A7 to
make it work as you originally described the problem.

--
Rick (MVP - Excel)


"Louise" wrote in message
...
Actually I worked it out - Thanks anyway..

Range("B7").Select
Do
If ActiveCell < nowmonth Then
ActiveCell.Offset(0, 1).Select
End If
Loop Until ActiveCell = nowmonth

ActiveCell.Offset(1, 0).Select


:)


"Louise" wrote:

Hi,

I have some data and the headers for the numbers are months. All the
months
are on row 7. I need to add some code to start looking in row 7 (cell
A7)
and look at each column to locate the relevant date entered in cell A1.

Example: The code needs to look at cell A7, then B7, then C7 etc etc
until
it locates the right value.

How can I do this please?

Thanks,




All times are GMT +1. The time now is 12:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com