+ Reply to Thread
Results 1 to 26 of 26

Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

  1. #1
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    I used to modifiy my macro each day and change the date then run the macro. Basically CTRL-F find/replace AABBCC with the corresponding MMDDYY date for that day then run the macro. I found out that this code...

    Please Login or Register  to view this content.
    ...would pull one date from the list in column A then run the macro and rinse and repeat for each Dt in DtRNG. The problem I am running into is I don't just need one date replaced. I need six different dates replaced. Is there a way I can replace the multiple dates without having to use CTRL-F to modify the macro each time. Below is pieces of the code that reference each date. Date1 and Date11 are the same date but different formats. I know I can use the above code to replace one of those dates but what about multiple dates?

    Please Login or Register  to view this content.
    Here is my thought process but its stops at one date

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    What exactly are you trying to do?

    Why are you using a loop if there's only one date?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    I don't need the loop for this macro I just took it from another macro someone made for me. I am not sure how else to explain what I am trying to do other than tyring to replace DATE1 and DATE11 with one date (DATE1 and DATE11 being the two formats I need it in) {Im not concerned with the formats I know how to do that its dimming them down into a way I can use it from the personal.xls columns A and B and so on i guess, DATE2 and DATE22 with the second date, and so on until DATE6 and DATE66. I know .....
    Please Login or Register  to view this content.
    ...will work for one date but what about the other 5? Can I do something like DtRNG and DT to be column A, then DtRNG2 and DT2 to be column B or something like that so that I can type the dates I need in personal.xls file in columns A and B and so on instead of using CTRL-F find/replace ?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Where are you trying to replace the date?

    In the code you've posted it appears to be in the path to the workbook(s) you want to open and you also seem to be putting the date in a cell in the workbook(s) you are opening.

  5. #5
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Here is the part of the code i could paste. We don't have to use the DtRNG and Dt if that is not going to work but maybe this might help with the thought of understanding what i am trying to accomplish i hope.

    Please Login or Register  to view this content.
    Last edited by Jack7774; 03-05-2013 at 03:26 PM.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    I'll look at the code, but an explanation in words might help too.

  7. #7
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    I have no clue how to explain it. I use CTRL-F to find and replace the word "DATE1" with example 020113 that is a date. I do the same thing for DATE11 and its the same date 02/01/13 but in this format.

    'CTRL-F REPLACE "DATE1" W/1ST DATE OF WEEK, FORMAT MMDDYY
    'CTRL-F REPLACE "DATE11" W/1ST DATE OF WEE, FORMAT MM/DD/YY
    'ETC...........................................................
    'CTRL-F REPLACE "DATE6" W/1ST DATE OF WEEK, FORMAT MMDDYY
    'CTRL-F REPLACE "DATE66" W/1ST DATE OF WEE, FORMAT MM/DD/YY

    I have another macro that basically does this very thing except it only does it for one date and I have multiple dates in this macro. Here is a small piece of it

    Please Login or Register  to view this content.
    All I have to do is type the date in cell A1 in the personal.xls sheet1 tab. I want to do something simular except i have 6 dates total that need to be replaced in the weeklyintegrationsetup macro.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    It was actually what the code is meant to do I was wondering about.

    Obviously you have a bunch of files you are opening copying from.

    Where are those files located and where are you copying to?

    Why do you need to change the date?

    Are the files being generated on a daily basis?

  9. #9
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    The files are located in the same directory "I:\ACCOUNTING\Clear Payments\2013\2013-02\Completed\"

    I need to change the dates because this macro is intended to run on a weekly basis
    Last edited by Jack7774; 03-05-2013 at 04:19 PM.

  10. #10
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    That directory will change based on the date as well.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    So the directory the files are in changes?

    If all the files are in the same directory you could declare the path as a constant.

    You would do this at the top of the code, and that's the only place it would need to be changed in the future.

    By the way, why not close each workbook you are opening once you've finished with it rather than closing them all at the end?

  12. #12
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    The directory changes. Each month a folder is made for that month. I don't know how to declare a constant or even if that would work with the directory changing each month. Closing them once I'm finished with them do something I am not aware of rather than doing it at the end? Speed up the processs slightly or something?

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    This code has the path declared as a constant, strPath, at the top, you can use that throughout the rest of the code and you'll only need to change it in one place.

    I've also added a few variables to reference the various worksheets.

    This is only for the first part of the code, not really looked at the rest yet.

    Actually the rest of the code seems quite different, it's manipulating the files being opened and doesn't appear to be copying anything from them to other worksheets/workbooks.
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Thats all the macro does is open files copy data from them and paste them into template. I am not sure how you are missing that part.

    I see you shortened the code, nice job. I didn't know the code language well enough to write it that way but i see now how each item works and what it does. The only problem I see so far is that

    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Still have the DATE1 and DATE6 in the file name which is the part I want to replace with each week's weekdays dates. Otherwise its shorter and looks awesome so far.

  15. #15
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    I might have missed it because with all the Activating/Selecting it's hard to see what's going on.

    As far as I can see, apart from the first two workbooks, you are manipulating the workbooks you are opening as well as copying.

    For example, this opens a workbook, does a bunch of formatting in that workbook, copies from it and then moves onto the next workbook.
    Please Login or Register  to view this content.
    As for DATE1 and DATE6, you could use constants or variables for them just as you are the path.

  16. #16
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Yes i manipulate the file name because the file name has a date in it that changes for each days date for each file name. And as far as using constant or variables i don't know how but that sounds like a plausible solution. As for what the code does it formats certain data, it enters a date, and it copies. I'm not interested in shortening it unless you feel you want to but the part that i am trying to achieve is avoid having to open the macro hold button control while pressing f using the find replace the date 1 date 2 date 3 date 4 date 5 date 6 into the actual dates which is the actual file name. If i could type the dates in as a constant or variable at the top that would be great but how do you do that?

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    You would do it the same way as the for the path, declare the dates as constants at the top of the module.

    Then that's the only place you'll need to change them.

    As for shortening the code, that is one reason for tidying up the code but it's also to make the code run faster and to make sure it's actually doing what it's supposed to do.

    I'll take a look at the code but I'll probably have to make a few guesses to work out what's going on.

  18. #18
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    So I would say what

    Const "?" = Date1
    Const "?" = Date2
    Const "?" = Date3
    Const "?" = Date4
    Const "?" = Date5
    Const "?" = Date6

    What about format if i do it this way?

    Also could i set the Const "?" = "A cell reference in the personal.xls sheet1 like B1 and put the date in the cell then manipulate the format from that point?

  19. #19
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    I can also tell you what each line is doing as well if its not written how you are used to reading it. LOOK FOR THE COMMENTS IN ALL CAPS AND WITH THE ' STARTING THE LINE AS WELL. MAYBE THIS WILL HELP.

    Please Login or Register  to view this content.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    This is the part of the code I wasn't following.
    Please Login or Register  to view this content.
    First you select A7, copy it, move 4 columns to the right, then down to the last row of data, then 3 columns to the left, then you copy again and finally paste.

    I think a sample workbook would probably clear up what's going on.

  21. #21
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Attached is a sample file. Basically that part of the code copies the data in that cell and essentially find the bottom of the column of a row that still has data and pastes the data in that cell in column a in that row then copies the data in the rest of the column. I wrote it this way because each day these files change in size and I don't know which cell it will need to copy and paste down to so that each row of data has that following date. I suggested to a superior that we just contact the company who made these reports just for us and add a date column on the report however its not very high on their priority list.
    Attached Files Attached Files

  22. #22
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Sorry, that doesn't really help as there's no data.

    If I run the code on the worksheet it's just copying blanks.

    I can understand that the data might change, but what is it you actually want to copy and where do you want to copy it to?

  23. #23
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    I can't give you the data unfortunately. If you would like to fill in the columns with data yourself you are more than welcome. I fail to see how you won't be able to see what the code is doing when the code itself tells you line by line what it does. I would suggest opening the sample file and running this code line by line intead of running the macro all at once to get a better understanding. I have put comments in the code line by line almost to help.

    Please Login or Register  to view this content.
    Does this help?

  24. #24
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Quote Originally Posted by jessebranum777 View Post
    So I would say what

    Const "?" = Date1
    Const "?" = Date2
    Const "?" = Date3
    Const "?" = Date4
    Const "?" = Date5
    Const "?" = Date6

    What about format if i do it this way?

    Also could i set the Const "?" = "A cell reference in the personal.xls sheet1 like B1 and put the date in the cell then manipulate the format from that point?
    I would still like an example of what you mean in order to setup those dates as constants as to what goes in the ? mark area I have no idea.

  25. #25
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    You've got it the wrong way round.

    Date1, Date2, ... would be the names of the constants/variables.

    They would be variables if you were to pull their values from a worksheet, which I think you might want to do.

  26. #26
    Forum Contributor Jack7774's Avatar
    Join Date
    08-31-2012
    Location
    Georgia, US
    MS-Off Ver
    Excel 2010
    Posts
    576

    Re: Macro DtRNG as Range, Dt as Range, Multiple Criteria or dates

    Thanks. I read some more forum posts about how to use constants as well. SOLVED

+ 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