Select a row with a specific value in a given range

mkingrey

New Member
Joined
Nov 2, 2005
Messages
49
In row 1 of my worksheet I have a list of headers that contain dates. I need to write vba code that will select the cell(header) with a specific value in it.

Example,

if myVariable="11/28/2005" then I want to select the cell(header) with a value of 11/28/2005.

Logically I planned on using the MATCH worksheet function and then the ADDRESS worksheet function to return the cell address and then set the selection to the resulting address: Range(returnedaddress).Select

.....but this didn't work because the ADDRESS worksheet can't be used in VBA.

Can anyone help b/c I'm stumped?...thanks...
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Lakelands01

Board Regular
Joined
Jul 14, 2005
Messages
56
If I understand this problem correctly, this code may help:

Private Sub FindMatch()
Dim MyVariable As Date
MyVariable = Range("a4").Value

Range("a1").Activate
While ActiveCell.Value <> ""
If ActiveCell.Value <> MyVariable Then
ActiveCell.Offset(0, 1).Activate
Else
MsgBox "Found Match at Cell: " & ActiveCell.Address
Exit Sub
End If
Wend
Range("a1").Activate
MsgBox "No Match Found"

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,111
Messages
5,570,257
Members
412,313
Latest member
pauloalex
Top