Select cells in column M, until today's date in column B

Yulyo

Board Regular
Joined
Jul 17, 2017
Messages
94
Hello all,

I need some help and i just can't figure it out by myself. So if you have a few minutes, please help.


I have an excel file with columns from A to X.
On column B, i have some dates, starting from 01.11.2018 (B2)
On column M, i have some values, stating from M2.


Please help me with a macro that can select the values on column M (from a given cell, let's say M5), until today's date is reached in column B.

Thank you in advance.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello,

An important question is related to your dates in Column B ...

Are they sorted ? ... If yes in which order ...?
 
Upvote 0
Hello James,

Yes, they are sorted, just like this:

01.11.2018
02.11.2018
03.11.2018
04.11.2018
05.11.2018
..........
 
Upvote 0
Hello again,

OK ... so you can use the Match() function to return both row numbers ... ( for your start and end dates ...)

HTH
 
Upvote 0
Thank for your answer James,
It's a little bit more complicated. I needed a VBA, because after the step above, i should copy the range and paste it as values on another sheet...
I will try the match function and see what i can do.
Cheers
 
Upvote 0
The below works for me with UK date formats...

Code:
Sub findToday()
Dim xRng As Range
Set xRng = Columns(2).Find(CDate(Date), , xlValues, , xlByRows, xlNext)
Range(Cells(5, "M"), Cells(xRng.Row, "M")).Select
End Sub

Not sure whether your dates as posted are "real" dates though as it is unusual to have periods used as date separators.
 
Upvote 0
Thank you Mark,
I am getting a "runtime error 91 / Object variable or With block variable not set" on this line:

Range(Cells(5, "M"), Cells(xRng.Row, "M")).Select

Regarding the dates, this is how excel format them for my country...
 
Last edited:
Upvote 0
Find the cell with today's date in it then in a blank cell put the formula =ISNUMBER(B2) in it changing the B2 to the cell reference of the cell with today's date in it.
Does the formula return TRUE or FALSE.
 
Upvote 0
What do you get with....

Code:
Sub findToday()
Dim xRng As Range
Set xRng = Columns(2).Find(Format(Date, "dd.mm.yyyy"), , xlValues, , xlByRows, xlNext)
Range(Cells(5, "M"), Cells(xRng.Row, "M")).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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