Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a value "less than" a variable.

Status
Not open for further replies.

exRP12Nuke

Technical User
Oct 5, 2011
49
US
Good afternoon,

I am trying to find and select rows that are less than a particular date. Here is my code so far T1 is the date that I am trying to find.
Code:
Sub MoveData()

    x = Range("T1")
    Dim LRS As Long
    Dim Dx As String
    Range("H:H").Select
        If WorksheetFunction.CountA(Cells) > 0 Then
            LRS = Selection.Find(What:="<x", After:=[H1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        End If
End Sub

What do I need to have inplace of "<x" to find values that are less than x?

Thanks!
 



Hi,

How about using the COUNTIF() spreadsheet funtion?

Do you REALLY need VBA to do this?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
No, I do not really need VBA to accomplish this, but it is a small part of a larger formatting macro that I have been working on. I want to be able to find the rows of data that occur prior to a set date and copy them over to a different sheet within the workbook.

Many people will be using this program, and I am just trying to make it as user friendly as possible with as few steps as possible.

Thanks!
 


find the rows of data that occur prior to a set date and copy them over to a different sheet within the workbook.
Your could find the rows that qualify, using the AutoFilter on the date column, or you could use MS Query to return the data you want to the other sheet.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
The dates are always changing, so using the autofilter code for VBA would not work (unless there is a way to use variables for that). I will look into MS Query when I get back to work tomorrow.

Thanks!
 


Turn on your macro recorder and record setting the date filter as required for a specific set of dates.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

I would follow Skip's advice, but for future reference I would try:
Code:
LRS = Selection.Find(What:=[blue]"<" & x[/blue], After:=[H1],

Have fun.

---- Andy
 
Thanks guys! Here is the starting point that I ended up with:

Code:
x = Range("T1")
    Range("H:H").Select
        If WorksheetFunction.CountA(Cells) > 0 Then
            LRS = Selection.Find(What:="*", After:=[H1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        End If
    Sx = "S" & LRS
    If Range("H3") > x Then GoTo ErrHandler2
    
    ActiveSheet.Range("$A$2", Sx).AutoFilter Field:=8, Criteria1:="<" & x

A lot of extra work on my end to make it simpler for others.

Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top