+ Reply to Thread
Results 1 to 15 of 15

Check Column A for date before running macro

  1. #1
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Check Column A for date before running macro

    Hello, I have some code here that I am using to find matches in Column D and then remove colored cell once the match is found. I am in putting the data line by line from a Barcode scanner and only want to run the macro if the date in Column A is today. Here is the code I am using.

    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 02-07-2014 at 05:20 PM. Reason: fixed code formatting

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Check Column A for date before running macro

    my guess would be something like putting an IF statement after the start of your FOR loop

    Please Login or Register  to view this content.
    this is untested....
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Check Column A for date before running macro

    Nu2Java, the leading stars in your code impair readability and make it impossible to copy and paste this code to test or modify it. I suggest you edit your text to replace each star with a space. The CODE tags will preserve the spacing; it's not necessary to insert leading characters to force the desired spacing. Thanks.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Check Column A for date before running macro

    Sorry for the code with leading stars, I pasted my code from my phone and somehow it added those stars.

  5. #5
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Check Column A for date before running macro

    Thanks judgeh59... I tried that but it seems to just exit the for loop no matter what the date is.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Check Column A for date before running macro

    I fixed the code formatting for you.

  7. #7
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Check Column A for date before running macro

    Thanks for fixing the code format. Does anyone have any ideas on what I am trying to accomplish here? Thanks in advance.... Cuz I'm stuck.

  8. #8
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Check Column A for date before running macro

    I need to update my original request. In my sheet, there can be hundreds of rows, and only maybe fifty rows that I want to run the macro for, which I want to run each day. So I want the macro to exclude all rows that are NOT the current day.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Check Column A for date before running macro

    I don't understand how your original request and your post immediately above are different. Anyway, insert the red code to process only those cells where the date in column A is not today.

    However, I am confused about what you are trying to do. Your first If statement uses Countif so that the cell will be processed only if it is a unique value within that range. Then you use Find to find other values, which it won't since the value is unique. Other than the day issue, does your code do what you want it to do?

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Check Column A for date before running macro

    Thanks for the help on this. Yes, my code does work how I need it to other than the date. How it works now is, in Column D I am entering part numbers and coloring the cell when NO duplicate is found. Once the duplicate is found, the cell color goes back to white. What I need is for the code to ignore the rows in Column D that are not today in Column A. So if I had a colored cell yesterday because of no duplicate, I want it to stay that way. I hope that makes sense.

  11. #11
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Check Column A for date before running macro

    Hi Nu2Java,

    I am not sure I totally understand, but try the code below which should be working with Excel 2003. Otherwise if you could upload your workbook without any sensitive data and we could go from there.
    Please Login or Register  to view this content.
    Cheers, berlan

  12. #12
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Check Column A for date before running macro

    Hi Berlan,

    Thanks for the reply and your help. I tried your code but get an error on "If Evaluate" Line. I will try to explain the best I can along with attached file. I will basically start this excel file lets say Today, and when I run the macro, all cells in Column D will turn a different color if no match is found (which is what I want). But what I need to add is, when I run this code tomorrow, I want the cells in Column D from today to remain colored as there was no match found yesterday. So like in my attached file, "PART_D" is the only one on 1/29/2014 that had a match and the cells are white. PART_A, PART_B, PART_C remain colored as they are on different dates, along with PART_D that is now on a new date. I hope I have explained it correctly. Thanks for your help.
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Check Column A for date before running macro

    Hi again, please try the attached

    Just a question when it comes to coloring your cells. For instance, PART_A (which has no duplicates for the latest date - in A1) will match the color of PART_A at a different date, is that what you want as well?

    Please Login or Register  to view this content.
    Cheers, berlan
    Attached Files Attached Files
    Last edited by berlan; 02-08-2014 at 07:39 PM.

  14. #14
    Forum Contributor
    Join Date
    04-03-2012
    Location
    Washington State
    MS-Off Ver
    Excel 365
    Posts
    340

    Re: Check Column A for date before running macro

    Hi Berlan,

    This is looking like EXACTLY what I need. If the colors can match for the different dates, that would be a GREAT addition, I had not thought of that. Thanks very much for your time and help.

  15. #15
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Check Column A for date before running macro

    You're welcome, glad I could help

    If you're satisfied by any members response to your issue in this thread, please use the star icon at the lower left of their post.

+ 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. Need to over ride compatiblity check message when running a macro
    By sakthisan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-21-2014, 05:51 PM
  2. Replies: 7
    Last Post: 10-04-2012, 01:32 PM
  3. [SOLVED] Check Criteria On Button Click Before Running Macro
    By swordswinger710 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-06-2012, 04:56 PM
  4. VBA Code to check cell before running macro
    By kolovel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-17-2010, 06:19 PM
  5. [SOLVED] How to check a cell for content before running macro.
    By Incoherent in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2005, 12:05 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