Solved

Find the row for a input

Posted on 2015-01-26
5
62 Views
Last Modified: 2016-02-10
How to write a VBA such that when a user input a given date, it will return the row number that are within the From & To date in the attached worksheet.

Tks
Test.xlsm
0
Comment
Question by:AXISHK
  • 3
5 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 150 total points
ID: 40570415
If the date is in cell D3, then the answer is

=MATCH(D3,A4:A78,1)+ROW(D3)
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40570457
Add this code to a module.

Sub FindRow()

Dim lngRow As Long
Dim dteFind As Date

dteFind = InputBox("Please enter the date")
With ActiveSheet
    For lngRow = 4 To .UsedRange.Rows.Count
        If dteFind <= .Cells(lngRow, 2) Then
            MsgBox "Found in row " & lngRow
            Exit Sub
        End If
    Next
End With
MsgBox "Date " & dteFind & " not found"
End Sub

Open in new window

0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 350 total points
ID: 40570482
Or you can return the row using a Function like this. The function will return row 0 if the date isn't found.

Usage:
Dim dte As Date

dte = "2/18/14"
MsgBox FindRow(dte)

Open in new window


Private Function FindRow(dteFind As Date) As Long

Dim lngRow As Long

With ActiveSheet
    For lngRow = 4 To .UsedRange.Rows.Count
        If dteFind <= .Cells(lngRow, 2) Then
            FindRow = lngRow
            Exit Function
        End If
    Next
End With
FindRow = 0
End Function

Open in new window

0
 

Author Closing Comment

by:AXISHK
ID: 40597731
Tks
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40598914
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now