+ Reply to Thread
Results 1 to 7 of 7

Hide rows in a worksheet if dates in two date column match - Macro

  1. #1
    Registered User
    Join Date
    12-26-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Hide rows in a worksheet if dates in two date column match - Macro

    Hi!
    In a worksheet I have two Date columns and want to hide those rows where dates in the column match. I have a recorded a macro and am not able to do this, please help.

    Thanks

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Hide rows in a worksheet if dates in two date column match - Macro

    Maybe:

    Please Login or Register  to view this content.
    Assumes the date Columns are A and B.

  3. #3
    Registered User
    Join Date
    12-26-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Hide rows in a worksheet if dates in two date column match - Macro

    Hi John,

    Thanks for the reply. I am doing macros first time so excuse me if I am wrong. You have mentioned assumption that date columns are A and B but in the code I can see only "A" and no "B". Do I have to replace 'A' in "In Range("A2:A" & ActiveSheet.UsedRange.Rows.count + 1)"? My actual date columns are 'EXPIRY_DATE' at F & 'TIMESTAMP' at O and sheet nos. are "Sheet3" & "Sheet5" containing this data. How will I change the code with this data? Secondly, in the code 'If rcell.Value = rcell.Offset(, 1).Value then', within parenthesis there is a "comma" but no parameter before that, is there something missing? Thanks again.
    Last edited by shailew; 12-26-2013 at 12:09 PM. Reason: For better clarity

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Hide rows in a worksheet if dates in two date column match - Macro

    No. The rcell represents items in Column A, whereas it is checking against rcell.Offset(,1) this is the value one column over (Column B). Therefore it will check column A against the value in Column B. If they match it will hide the row for the item. The Offset command tells it where to look. Offset(row,column). Since the rcell range is on the same row you leave the row offset blank. The one tells it to look one column over. Offset(,1). Same row one column over. Hope that helps.

  5. #5
    Registered User
    Join Date
    12-26-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Hide rows in a worksheet if dates in two date column match - Macro

    Hi John,

    Thank you so much. Your code worked perfectly. I want one more help. Hidden rows did not solve my purpose, how can I delete these rows instead? I tried changing "delete" with "hidden = true" but it did not work out. What changes do you need to deleting the rows in the same code?
    I further wanted to tell you that I was worried about the size & complexity of the code for my above query but it was so simple and compact and I really appreciate that. Thanks again.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Hide rows in a worksheet if dates in two date column match - Macro

    Try:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-26-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Hide rows in a worksheet if dates in two date column match - Macro

    Thank u so much John. It worked perfectly.

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Hide rows in a worksheet if dates in two date column match - Macro

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. Countifs to count rows with a date which match a range of dates
    By pharmerjoe7 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-07-2013, 06:19 AM
  2. Macro to automatically hide rows by date
    By dominmoscow in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2013, 08:53 AM
  3. [SOLVED] VBA macro that hide and unhide column to respective rows based on first column value
    By janine6192 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2013, 06:21 PM
  4. How do I create a macro which hide dates, copies information to another worksheet?
    By naixiaki in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2010, 07:49 AM
  5. Hide rows where dates don't match
    By mainemojo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2009, 10:55 AM

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