Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find the row for a input

Posted on 2015-01-26
5
Medium Priority
?
68 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
[X]
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
  • 3
5 Comments
 
LVL 24

Assisted Solution

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

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

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 49

Accepted Solution

by:
Martin Liss earned 1400 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 49

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

618 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