+ Reply to Thread
Results 1 to 3 of 3

Date limit on formatting.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Date limit on formatting.

    I am trying to add some new flexibility to an existing macro but have been unable to do it successfully.

    As it stands now the macro will take the Name on Sheet2 B1, and then sort through the data in Sheet1 and nicely format it by color back on Sheet2 J1:Q.

    I now need to be able to limit the date using B2 on Sheet2. So if the data being worked on is greater than that date it should skip it.

    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,097

    Re: Date limit on formatting.

    Try twice (at least ) and comment
    Sub subgen99()
    Set ws1 = Sheets("Sheet1") 'change as necessary
    Set ws2 = Sheets("Sheet2") ' "
    Dim Max_Date  As Date, WkDate As Date
    ws2.Range("J2:" & ws2.Columns("J:Q").SpecialCells(11).Address).ClearContents ' clear the color table
    
    dt = ws1.Range("J1").Value
    n = ws2.Range("B1").Value ' the name to look for
    Max_Date = ws2.[B2]
    
       Set c = ws1.Columns(2).Find(n, lookat:=xlWhole) 'search for the name
       If Not c Is Nothing Then 'if the name is found
           firstAdd = c.Address 'noting the first found cell
           Do ' now we're gonna add data to the approiate columns using a Do Loop
               Set d = c 'we need to do this b/c we're gonna search for the right color column
               Set c = ws2.Rows(1).Find(c.Offset(0, 1).Value) ' look for the column color
               If Not c Is Nothing Then
                   If (d.Offset(0, -1) <= Max_Date) Then
                      r = ws2.Cells(Rows.Count, c.Column).End(3).Row + 1 'The empty row in the color column
                      ws2.Cells(r, c.Column).Value = d.Offset(0, -1).Value 'the date
                      ws2.Cells(r, c.Column + 1).Value = d.Offset(0, 2).Value 'the amount
                   End If
               End If
             Set c = ws1.Columns(2).Find(n, lookat:=xlWhole, after:=d) 'find the next name
           Loop While Not c Is Nothing And c.Address <> firstAdd
       End If
    End Sub
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Date limit on formatting.

    Works perfectly. Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Date Function to limit cell to receive only a date
    By dinosaur1993 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-02-2013, 07:40 PM
  2. conditional formatting - 3 rules limit
    By boarders paradise in forum Excel General
    Replies: 8
    Last Post: 07-18-2011, 02:49 AM
  3. To get around Conditional formatting limit
    By dantonic in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-06-2011, 01:37 AM
  4. excel formatting limit
    By navwelch in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-14-2011, 08:43 AM
  5. Conditional formatting limit
    By Jonathan78 in forum Excel General
    Replies: 20
    Last Post: 09-06-2009, 12:56 PM
  6. Conditional formatting beyond 3 criteria limit
    By ndp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2007, 11:39 PM
  7. Limit to Amount of Conditional Formatting?
    By jimmeh in forum Excel General
    Replies: 0
    Last Post: 04-20-2005, 01:51 PM

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.6.0 RC 1