Locate Value in a set Row, with Dynamic Column

L

Louise

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,
 
L

Louise

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


:)
 
R

Rick Rothstein

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top