Macro to select a range based on the value of a cell

danelskibr

Board Regular
Joined
Dec 31, 2014
Messages
58
Hello,

I am looking for assistance in creating a macro that will select a range based on the value of a cell.

In cell A1 I have a date. In row 3, I have date headers.

I would like the macro to find the cell in row 3 that matches the date in cell A1, and then select a range beginning directly beneath the header row and down 100 rows.


For example:

Cell A1= 10/1/2016.
The location of 10/1/2016 in my header row is cell D3.

The macro would find 10/1/2016 in cell D3 and select the 100 rows beneath that cell (range of D4:D104).


Thank you in advance for your help!

Brett
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Maybe:

Code:
Sub SelectDate()

    Rows(3).Find(Range("A1").Value).Offset(1, 0).Resize(100, 1).Select
    
End Sub
This will generate an error if the value is not found.
 
Last edited:
Upvote 0
If you want to avoid the error if the value is not found try:
Code:
Sub GetMeADate()
Dim F As Range
Set F = Rows(3).Find(Range("A1").Value, , xlValues, xlWhole)
If Not F Is Nothing Then F.Offset(1).Resize(101).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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