+ Reply to Thread
Results 1 to 14 of 14

Print selected rows based on cell data

  1. #1
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Print selected rows based on cell data

    I've been trying to find a macro that I could adapt to select rows that contain "No" in col J and Preview / print only those rows, in landscape. Only cols a to J contain data.

    Ideally, I'd like rows 2 to 15 to be always included at the top of the print.

    So far I've drawn a blank so any help appreciated.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Print selected rows based on cell data

    Try this:

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Print selected rows based on cell data

    Thanks for taking the time to help.

    However the code provided, is giving the following error.
    Runtime error 1004
    Autofilter of range class failed

    Hope you can help to fix it.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Print selected rows based on cell data

    When you run the macro and get the error code, click on debug and advise which line of code is highlighted. I am unable to duplicate your error message. Suggest you post a sample of your workbook so that it can be analyzed. The code works perfectly for me based upon your description in the first post.
    Last edited by alansidman; 10-02-2016 at 10:46 AM.

  5. #5
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Print selected rows based on cell data

    This is the line throwing the error.

    ActiveSheet.Range(Cells(16, 1), Cells(lr, lc)).AutoFilter Field:=10, Criteria1:="No"

    thanks

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Print selected rows based on cell data

    unable to replicate the error as that code works for me in my mocked up spreadsheet. Suggest again you upload your worksheet, sanitized for confidential data.

  7. #7
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Print selected rows based on cell data

    For some reason the forum reply mechanism won't allow me to attach a document, done it successfully many time before.
    I will keep trying

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Print selected rows based on cell data

    Have you tried this method.

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

  9. #9
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Print selected rows based on cell data

    Ok think it's attached ok now.
    Attached Files Attached Files

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Print selected rows based on cell data

    Solved:
    Please Login or Register  to view this content.
    In my code, I was declaring the last column in row 1. You have no row one data. I changed it to row 2. It should work for you now.

  11. #11
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Print selected rows based on cell data

    Brilliant, thank you.

    One further point, the sheet remains filtered after running the macro. Is it possible to include in the macro to clear the filtering thereby returning the sheet to it's original state ?

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Print selected rows based on cell data

    Add this line of code above the End Sub line

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-10-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    272

    Re: Print selected rows based on cell data

    Perfect, thank you for you help.

  14. #14
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Print selected rows based on cell data

    You are welcome and thanks for the rep.

+ 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. Macro to pull all rows of data based on an item selected in drop down
    By owensjb2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-14-2015, 10:35 AM
  2. Deleting selected data based on cell value
    By Jignesh Sardesai in forum Excel General
    Replies: 4
    Last Post: 11-05-2013, 03:35 AM
  3. Need Fix for Code To Print Selected Rows On One Sheet
    By elance in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-01-2010, 04:08 PM
  4. Selectively print rows based on cell data
    By MnMShow in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-07-2010, 01:38 PM
  5. Print selected & multiple rows to a form
    By seanyeap in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-29-2008, 07:27 AM
  6. [SOLVED] How do I print selected rows?
    By kmf in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 07-31-2006, 01:58 PM
  7. [SOLVED] Create a report with selected rows based on the content in a cell
    By ThirdTim in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 05-05-2005, 01:06 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