+ Reply to Thread
Results 1 to 2 of 2

Thread: Higlight a row based on a date

  1. #1
    Registered User
    Join Date
    09-07-2011
    Location
    Washington, DC
    MS-Off Ver
    Excel 2007
    Posts
    1

    Higlight a row based on a date

    I am trying to highlight a row based on a date. I am tryin to use the DATEVALUE on a range field and am getting a data type mismatch. Any ideas on how to restructure my code to get around this? Thanks


    Dim r as range
    Dim myrange as range
    
    For Each objws In objwb.Worksheets
    If Right(objws.Name, 6) = "Detail" Then
    'MsgBox objWS.Name
    'ws.ResetAllPageBreaks
    objws.Activate
    lastrow = objws.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    'LastCol = objws.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
    
    Set myrange = objws.Range(objws.Cells(3, 1), objws.Cells(lastrow, 20))
    Set myrange = myrange.Rows("1:" & myrange.Rows.Count)
    For Each r In myrange.Rows
    If (r.Cells(, 13) = "OPEN") And DateValue(r.Cells(, 6).Value < DateValue(Me.txt_cfodate)) Then
    r.Interior.ColorIndex = 3
    r.Cells(, 3).NumberFormat = "$#,##0"
    r.Cells(, 3).HorizontalAlignment = xlRight
    r.Cells(, 4).NumberFormat = "$#,##0"
    r.Cells(, 4).HorizontalAlignment = xlRight
    r.Cells(, 5).NumberFormat = "$#,##0"
    r.Cells(, 5).HorizontalAlignment = xlRight
    r.Cells(, 6).NumberFormat = "$#,##0"
    r.Cells(, 6).HorizontalAlignment = xlRight
    r.Cells(, 7).NumberFormat = "$#,##0"
    r.Cells(, 7).HorizontalAlignment = xlRight
    r.Cells(, 8).NumberFormat = "$#,##0"
    r.Cells(, 8).HorizontalAlignment = xlRight
    End If
    
    Next r
    i = i + 1
    
    queryname = "A1:T" & lastrow
    objws.PageSetup.PrintArea = queryname
    
    End If
    Next objws
    Last edited by armesca; 09-07-2011 at 01:21 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Higlight a row based on a date

    Hello armesca,

    Welcome to the Forum!

    This is probably the cause of the your problem...
    DateValue(Me.txt_cfodate)

    If the text box is in a UserForm then this definitely the cause. The reason is the "Me" keyword would refer back to the worksheet and not the UserForm.If it is on a UserForm, you will need to qualify the reference with the UserForm's name and the UserForm must be loaded into memory when this code runs or you will encounter another error.

    UserForm Reference
    Change the name of the UserForm to what you are using.
    DateValue(UserForm1.txt_cfodate)
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0