set variable to row value of date found in range

Posted on 2011-09-06
Last Modified: 2012-05-12
in Column A on Sheets("Charts") there is a list of dates.  I need to set variable FindToday to the row number of today's date
Question by:KnutsonBM
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 18

Expert Comment

ID: 36491256
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 36491268

LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 36491284
FindToday = worksheetfunction.match(date,Sheets("Charts").range("A:A"),0)
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.


Author Comment

ID: 36491294
Sub Asearch()
Dim FindToday As Integer
FindToday = WorksheetFunction.Match(Date, Sheets("Charts").Range("A:A"), 0)
If FindToday Is Nothing Then
    MsgBox "Not found"
    MsgBox "Found on row " & FindToday
End If
End Sub

this gives me a 'Type Mismatch'
LVL 43

Accepted Solution

Saqib Husain, Syed earned 250 total points
ID: 36491721
Then try this

Sub Asearch()
Dim FindToday As Integer
On Error Resume Next
FindToday = Application.Match(Date * 1, Sheets("Charts").Range("A:A"), 0)
On Error GoTo 0
If FindToday = 0 Then
    MsgBox "Not found"
    MsgBox "Found on row " & FindToday
End If
End Sub

LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 250 total points
ID: 36494732

For Each Cell in Range("A:A")

If Cell.Value2 = Date * 1
Then R = Cell.Row
Exit Sub
End If
Next Cell

Open in new window

This will give the first occurence of today's date, if you want the last occurence remove line 5 "Exit Sub".

Rob H

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question