+ Reply to Thread
Results 1 to 8 of 8

How to remove rows that contain current date (mm/dd/yyyy)

  1. #1
    Registered User
    Join Date
    05-20-2015
    Location
    United States
    MS-Off Ver
    Microsoft Office 2013
    Posts
    36

    How to remove rows that contain current date (mm/dd/yyyy)

    Hello everyone,

    Below is a Macro that I am trying to create that will automatically take and format data on two newly created Workbooks. The problem I am running into is that I need to remove all the rows that contain the current date. I have bolded the portion of the code that is giving me trouble. I am new to VBA within excel, and any help would be greatly appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to remove rows that contain current date (mm/dd/yyyy)

    Looks pretty good so far. I usually use range.entirerow myself.

    Please Login or Register  to view this content.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    05-20-2015
    Location
    United States
    MS-Off Ver
    Microsoft Office 2013
    Posts
    36

    Re: How to remove rows that contain current date (mm/dd/yyyy)

    Hey daffodil11,

    Thank you for the very quick reply. I added your portion to my code, but for some reason it still will not remove my rows containing today's date. My dates are located in Column E on my first workbook. Is my range incorrect? Below is my updated portion. Do I take the "Dim lRow as Long" and "Dim iCntr As Long" out?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to remove rows that contain current date (mm/dd/yyyy)

    I see the issue now. The argument of Cells is (row #, column #).

    Your dates are in Column E, which is Column 5. Therefore

    Please Login or Register  to view this content.
    should be

    Please Login or Register  to view this content.
    The proceeding line should specify only a single cell.

    Range("E" & iCntr).EntireRow.Delete

    E:E would be all of the cells. That would be bad. It would delete everything.

    Please Login or Register  to view this content.
    This should do it just fine.

    And technically, the Column value of the EntireRow.Delete line is irrelevant because all Columns of a given cell are on the same row of that cell.

    This snippet would function no different

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-20-2015
    Location
    United States
    MS-Off Ver
    Microsoft Office 2013
    Posts
    36

    Re: How to remove rows that contain current date (mm/dd/yyyy)

    Thanks again for the prompt response, and especially spelling it out. That makes a lot more sense. For some reason though, it is still not removing the rows with today's date. Below is my updated portion. My other rows contain things such as, names and email addresses. This shouldn't conflict, correct?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to remove rows that contain current date (mm/dd/yyyy)

    lRow needs to be defined

    Please Login or Register  to view this content.
    This identifies the last row so it knows where to start counting.

    Without the variable, you could always use something static such as

    Please Login or Register  to view this content.
    Last edited by daffodil11; 05-21-2015 at 08:27 PM.

  7. #7
    Registered User
    Join Date
    05-20-2015
    Location
    United States
    MS-Off Ver
    Microsoft Office 2013
    Posts
    36

    Re: How to remove rows that contain current date (mm/dd/yyyy)

    That seems to have done the trick! I really appreciate the help. At first it was not working, because I had the range as "Z", when my values were actually in "E". So I just switched them around and it worked. This is what I ended up with:

    Please Login or Register  to view this content.

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: How to remove rows that contain current date (mm/dd/yyyy)

    No problem. Glad I was able to help you out.

    I only started teaching myself code last year.

+ 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. Replies: 8
    Last Post: 10-02-2013, 06:23 PM
  2. Replies: 7
    Last Post: 11-18-2012, 02:28 PM
  3. [SOLVED] Imported data contains strings dd.mm.yyyy how can I convert to date format dd/mm/yyyy inVB
    By Boormo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-05-2012, 05:48 PM
  4. [SOLVED] add current time (hh:mm:ss) as well as current date (dd:mm:yyyy) into the code
    By papasideris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2012, 02:29 PM
  5. [SOLVED] opening excel file -> date format problem: DD/MM/YYYY vs MM/DD/YYYY
    By yung in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2005, 09:06 AM

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