+ Reply to Thread
Results 1 to 9 of 9

find date and run macro

  1. #1
    Registered User
    Join Date
    10-18-2008
    Location
    michigan
    MS-Off Ver
    2010
    Posts
    88

    find date and run macro

    Hi

    Hi,
    I’m trying to have the cursor go to today’s date and run a sub routine ( todaydate). If today’s date is not yet entered, I want to go to yesterday’s date and run a different sub (yesterdaydate )
    I can get the code to work without the subs. Thank you Sindhus.
    But, It will find todays date and run the code “todaydate”. Then, Instead of Exit Sub, it finds yesterday’s date and runs “yesterdaydate”, also.
    The spreadsheet will always have yesterday’s date, but not always today’s.

    HTML Code: 

    Mike

  2. #2
    Registered User
    Join Date
    10-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: find date and run macro

    The code below is untested but I believe it should work. You'll need to change the Sheets(1).Range("A:Z") to whatever the sheet and range is that you want the code to look through to find the date.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-18-2008
    Location
    michigan
    MS-Off Ver
    2010
    Posts
    88

    Re: find date and run macro

    Hi snax,
    I tried your code but it seems to have a problem
    I kept the-- With Sheets(1).Range("A:Z")since the sheet is sheet1 and the date column is "A"
    The cursor does not find any date. It does run the first code (yesterdaydate)where ever the cursor is.
    I tried again after I made a range for the date column and renamed the sheets----With Sheets("2012").Range("date1")---- but still got the same results.

    Mike

  4. #4
    Registered User
    Join Date
    10-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: find date and run macro

    What is the exact value of the cell that the macro should find? If the cell has anything else besides the date (i.e.: if it has a time stamp) then the macro will never find the date the way the code is currently set up.

  5. #5
    Registered User
    Join Date
    10-18-2008
    Location
    michigan
    MS-Off Ver
    2010
    Posts
    88

    Re: find date and run macro

    some will be made using a macro:

    HTML Code: 
    and some will be just typing in the date with the above format

    I can change to have it put in in any manner as long as the final result is in the above format



    Mike

  6. #6
    Registered User
    Join Date
    10-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: find date and run macro

    It worked for me using the formula you provided and the code from my previous post. As long as the worksheet/range reference has the cell(s) that you are looking for then I don't see why it wouldn't work.

  7. #7
    Registered User
    Join Date
    10-18-2008
    Location
    michigan
    MS-Off Ver
    2010
    Posts
    88

    Re: find date and run macro

    I'm probably doing something wrong

    I won't be able to try it till latter tonight. I'll get back tomorrow


    thanks


    Mike

  8. #8
    Registered User
    Join Date
    10-18-2008
    Location
    michigan
    MS-Off Ver
    2010
    Posts
    88

    Re: find date and run macro

    I'm using Excel 2010

    I opened a new worked book. In A4 i typed in yesterday's date --12/7/2012. in A10, i typed in today's date --12/8/2012.

    I put in your code in Module 1

    I also put in the following codes

    HTML Code: 
    HTML Code: 
    What happens is the cursor will move over one cell to the right and type in "this is yesterday" where ever it is.

    it doesn't seem to look for anything in A column. i did the "step into' (F8) and it runs the first macro and ends. i tried with and without today's date typed in

    Also I noticed that there is no reference to look for yesterday's date.

    I'm new to macros and this is how I'm trying to learn. I pick up bits and pieces here and modify it to suite my needs.

    As I said before...I'm trying to have the cursor go to today's date and run a macro. if there is no today's date, then go to yesterday's date and run a different macro.. there will always be yesterday's date, but not always today's. The dates will always be in column A and the sheet name is the default (sheet1) After I get it to run, i will put it in the Sheet1 module(?)and change the name to "Private Sub Worksheet_open()".


    Mike

  9. #9
    Registered User
    Join Date
    10-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    39

    Re: find date and run macro

    I don't think I completely realized what you wanted. I think the code below should resolve your issues. In order for you to have it work when the workbook is opened, you will have to place the macro in the "ThisWorkbook" module instead of "Module1" or any other module. If the code below doesn't work, try clicking on the blank column in between where the code goes and where all the modules are. If you do it correctly, a red circle will appear. This creates a break in the code so that when the code gets to that line it stops before it is executed. This is helpful for finding where the code isn't working properly. Try finding out what line(s) aren't working as you would expect and either modify it to work the way you want it to or post the code that you have and the issue you see and hopefully it can get resolved.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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