+ Reply to Thread
Results 1 to 21 of 21

Search between two dates and copy columns

  1. #1
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Search between two dates and copy columns

    Hello everyone,

    I would like some help on this task.

    I need a script which searches between two dates in a column and then copies the entire corresponding columns between these two dates and pastes them to another sheet.


    Please, pay attention that the date is in the format: d.m.yyyy hh:mm

    Here is a sample:
    sddssd.png


    Link to crosspost:
    http://www.mrexcel.com/forum/excel-q...y-columns.html

    UPDATE. I am sorry I didnt know about that rule for another forum. My apologies.
    Last edited by bowdown; 08-23-2016 at 10:45 AM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    Do you mean copy and paste the matching ROWS?

    Try something like:
    Please Login or Register  to view this content.
    You may need to tweak this depending on how you are obtaining your date criteria, and where you want to paste the output....
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    Thanks Olly, is there anyway I can enter the dates withing the sheet not in the macro? Yes, I mean copy and paste the matching rows.

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    Quote Originally Posted by bowdown View Post
    Thanks Olly, is there anyway I can enter the dates withing the sheet not in the macro?
    Yes, of course. Tweak this section:
    Please Login or Register  to view this content.
    to something like:
    Please Login or Register  to view this content.
    That's just an example, where your start date is in Sheet1 range F1, and your end date in Sheet1 range G1. You get the idea.

  5. #5
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    Where should I paste the data with the columns and dates if start date is in F1 and end date in G1

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    I don't understand your question.

    It might be easier to help you get the code precisely right, if you were to attach a sample workbook, which shows your source and target data structures - that is, where is the data coming from, where are the date criteria, and where do you want the matching rows pasted?

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Search between two dates and copy columns

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this http://www.excelguru.ca/content.php?184 to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    Glad to have helped! If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. It'd also be appreciated if you were to click the add Reputation button at the foot of any of the posts of those who helped you reach a solution.



    http://www.mrexcel.com/forum/excel-q...y-columns.html
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  8. #8
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    dddd.png

    Here is what I mean:

    If you have dates in column E which are between the dates in B and C, COPY the dates together with the price from column E and F and paste them into column H and I for the first Open-Close pair, J and K for the second Open-close pair and so on.

    I am really grateful that you respond and trying to help.


    Cheers

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    Did you read oeldere's post?

    Attach a workbook, not an image.

  10. #10
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    I am sorry i didn't read it properly. Here is the file.

    So if the date in 'F' column is between the date in 'A' and 'B', I need to copy the F date + the price ('G' column) in lets say 'J' and 'K' (that is for the first Open-Close and so on). Then I need to pick the second pair Open-Close and do the same check and copy in lets say M and N.
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Search between two dates and copy columns

    Please Login or Register  to view this content.
    1) To who you are replying?

    2) did you read #7?

  12. #12
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    Quote Originally Posted by oeldere View Post
    Please Login or Register  to view this content.
    1) To who you are replying?

    2) did you read #7?
    1) I am replying to #6, Olly.
    2) Yes I did and I posted a link of the crosspost and I apologize I didnt know about that rule.

  13. #13
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    You could try something like this:

    Please Login or Register  to view this content.
    Be careful, though - you are VERY nearly running out of columns, with this dataset. I'm not sure what you're actually doing with the output, but I'd suggest a different structure of output, to prevent errors caused by trying to use too many columns, if your dataset increases.

  14. #14
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    Thanks Olly, I tested it, it works great. I really appreciate your work.

  15. #15
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. You can also 'Add Reputation' to users who have helped you. Thanks.

  16. #16
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    Hi Olly,

    Thanks again for the macro. However, I tried it on a different PC and it doesnt work. I mean it runs out, no errors but nothing happens.

    Also, when I click 'Step Into', it highlights the first sub() line.

    I tried different macro code as msgbox "hello" and it worked.

    Macros are enabled. My excel version is 2013.


    Any thoughts?

  17. #17
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    The code handles errors by writing the error message to the immediates window. So you could look at the immediates pane (press Ctrl G in the VBE) to see what error is happening.

    To debug more fully , comment out the following line:
    Please Login or Register  to view this content.
    which will cause the procedure to break on an error. Let me know what happens then - which error type is being thrown, on which line?

  18. #18
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    Quote Originally Posted by Olly View Post
    The code handles errors by writing the error message to the immediates window. So you could look at the immediates pane (press Ctrl G in the VBE) to see what error is happening.

    To debug more fully , comment out the following line:
    Please Login or Register  to view this content.
    which will cause the procedure to break on an error. Let me know what happens then - which error type is being thrown, on which line?
    Immediate window is empty. No error shown on any line.

  19. #19
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    Have you commented out the "On Error Goto Terminate" line, then run the procedure? And there is NO error?

    Please attach the workbook you are trying to use.

  20. #20
    Registered User
    Join Date
    08-19-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    12

    Re: Search between two dates and copy columns

    Quote Originally Posted by Olly View Post
    Have you commented out the "On Error Goto Terminate" line, then run the procedure? And there is NO error?

    Please attach the workbook you are trying to use.
    Yes, I tried with the comment out. Here is the file.
    Attached Files Attached Files

  21. #21
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Search between two dates and copy columns

    Okay, well that attachment works perfectly for me...

+ 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. Search multiple columns of dates and send reminder email 30 days before expiry
    By prh2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2013, 12:47 AM
  2. search 2 different columns for same information and copy entire row
    By Biogeek1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 08:44 AM
  3. [SOLVED] Search for Value in multiple columns and copy the value in column A to new sheet
    By hallr7 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-02-2013, 11:20 AM
  4. [SOLVED] How to search across 2 columns for keywords from a list and copy each row to a new sheet?
    By keithtran12 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 04-01-2013, 05:16 AM
  5. [SOLVED] Search Copy and Paste two columns in different sheet
    By mahtabshaikh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2012, 01:26 PM
  6. [SOLVED] Search and copy value based for multiple columns
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2011, 12:23 PM
  7. Search for 3 specific columns and copy
    By csynic in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-06-2011, 04:43 PM
  8. Mass search columns and copy
    By chambone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2009, 12:24 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