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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
12,669
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

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
18,144
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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,195,619
Messages
6,010,736
Members
441,567
Latest member
Flitbee

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
Top