+ Reply to Thread
Results 1 to 19 of 19

Dialogue box to search date range of table column, copy relevant rows to report sheet

  1. #1
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Question Dialogue box to search date range of table column, copy relevant rows to report sheet

    Thanks in advance for your help. I want an excel vb macro to when button pressed, deletes all cells in report sheet; opens a dialogue box requesting the date search range; goes to data sheet and searches column b for all rows that have dates within the range; copies rows and pastes them with the headings row to the Report Sheet.

    My macro is close to working but I can't shake the bugs, see below...

    Please Login or Register  to view this content.
    Last edited by arlu1201; 08-26-2013 at 03:08 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Hi,

    Could you please upload a workbook with this code in it so that I may see the code in context to have some chance of debugging it?

    Or alternatively, tell me where your code is falling over (which line) and what error message is displayed.

    Thanks

  3. #3
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Please find mockup spreadsheet attached
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Hi,

    Your code appears to be breaking on the line
    Please Login or Register  to view this content.
    Now I haven't dealt with Excel tables much using VBA, but I'm not actually sure what the
    Please Login or Register  to view this content.
    part of this line is supposed to be achieving. If this is removed, then cell A1 is selected (is this what you were attempting to do???).

    Another thing that may be bringing you unstuck is that Excel 2003 tables don't use the square brackets in VBA to the best of my knowledge, that is only since Excel 2007. Unfortunately I don't have Excel 2003 so I can't debug your code in the same environment

    Let me know if either of these observations have helped

  5. #5
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    I am using MS Excel 2010. Regarding the break with the headers, this was caused because I change the name of one of the headers in the data sheet and forgot to update the formula (sorry). I have now fixed with the line - Range("Table2[[#Headers],[Committee]:[File path to documents]]").Select

    The break causing the problem is the line - For Each cell In Range("B1:B500").Offset(A - 1, 0)

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Ah sorry about that, it says you are using Excel 2003 on your user profile.

    The problem with that line is that the Range.Offset property expects its RowOffset and ColumnOffset arguments to be positive, negative or zero. You are entering a RowOffset of "A - 1", which is a valid parameter if and only if "A" was defined as a variable or a constant with an integer-type value (which it is not in your code).

    To allow me to propose to you a valid alternative, could you please explain what you were attempting to achieve with this line of code? Which range of cells were you trying to loop through?

    Thanks

  7. #7
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    I want the macro to search dates that fall within a range (column b lists dates for each row), and for each date that falls in the range the corresponding row should be copied and added to the report. It is just that one line that has the bug and I think your right in that it probably needs to be defined earlier. Your help is appreciated.

  8. #8
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    No worries Tim, happy to help!

    Please don't forget to mark this thread as solved and click on the * next to my post to say thanks

    Have a great day!

  9. #9
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Sorry, I don't think you uploaded the solution?? Thanks again in advance for solving it.

  10. #10
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Whoops, no I didn't.

    But before I can solve it anyway, I need you to tell me which row you are attempting to reference with the "A - 1"?

    Thanks

  11. #11
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    All the rows in the Data Sheet.

  12. #12
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    OK then, try just removing the .Offset() altogether then, as this should then cycle through all cells from B1 to B5000. So
    Please Login or Register  to view this content.
    will become
    Please Login or Register  to view this content.
    Let me know

  13. #13
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    While no error message came up, not data was copied into report.

  14. #14
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Try replacing this code
    Please Login or Register  to view this content.
    with this code
    Please Login or Register  to view this content.
    Let me know if this is copying what you want copied.

    Sorry this has taken so many attempts, but it is hard to guess what it is that you want because it has not been made perfectly clear, and your code shows no real indication either (which is why it is not working).

    Hope this helps

  15. #15
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Thanks again airyan, my apologies for not being more concise. That seems to be working but any chance of copying the whole row (if relevant) across to the Report Sheet, rather than just the cell in column a?

  16. #16
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    No problems!

    Sure, replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    and to copy all of the headers also, replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    Hope this is better

  17. #17
    Registered User
    Join Date
    08-18-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Thanks, this works. Find the final product below (in Excel 2010) for those who want to use it (noting that it only searches by year, not date range at present)...
    Please Login or Register  to view this content.
    Last edited by arlu1201; 08-26-2013 at 03:09 AM.

  18. #18
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    That's great news!

    Thanks for posting the final solution also Tim.

    Please don't forget to mark this thread as solved and click on the * next to my post to say thanks

  19. #19
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Dialogue box to search date range of table column, copy relevant rows to report sheet

    Tim,

    Welcome to the forum.

    I have added code tags to your posts. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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 string in a column then copy entire rows to another sheet
    By vannylette in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-12-2013, 12:16 PM
  2. Copy Column to relevant column by date
    By cloudwalking in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2013, 06:53 AM
  3. Replies: 3
    Last Post: 08-16-2012, 03:25 PM
  4. Copy rows to new sheet based on date range selected on a form
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-19-2009, 11:40 AM
  5. Copy Rows In New Sheet Based On Date Range Criteria
    By ahmedwaseem2000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2006, 05:45 AM

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