+ Reply to Thread
Results 1 to 5 of 5

macro to print worksheet based on value in range of cells

  1. #1
    Registered User
    Join Date
    04-27-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    10

    macro to print worksheet based on value in range of cells

    I have a workbook with two worksheets. I need a macro to print worksheet1 if worksheet2 has the value "X" (either caps or lowercase) in range A1:A3000. Can anyone help with this?

    Thanks

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    re: macro to print worksheet based on value in range of cells

    A good place to start
    http://www.excelforum.com/excel-prog...int-areas.html
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    re: macro to print worksheet based on value in range of cells

    then try some thing like

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    04-27-2009
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: macro to print worksheet based on value in range of cells

    Thanks for your reply, but I am still not sure how to do this. This is what I have and it only prints if I enter an x in cell a5, which is offset 4 from A1. I want it to print if x is in any cell from a4:a3000. A1 has the name of the sheet I want to print. I have another macro at the "on change" that will run 3 macros one right after so I don't need this macro on change. Thanks for your help.

    Sub PrintCM()
    '
    ' PrintCM Macro
    '
    Dim bFirst As Boolean, sh As Object
    Dim cell As Range
    Set sh = ActiveSheet
    bFirst = True
    For Each cell In Worksheets("CopyFrom").Range("a1:a1")
    If LCase(cell.Offset(4, 0).Value) = "x" Then
    Worksheets(cell.Value).Select Replace:=bFirst
    bFirst = False
    End If
    Next
    If Not bFirst Then
    ActiveWindow.SelectedSheets.PrintOut
    sh.Select
    End If

    End Sub

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: macro to print worksheet based on value in range of cells

    Hello mugs62,

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code using the # icon
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    To manually insert the tags
    Use the Bulletin Board Code Tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] at the end of the last line.


    To learn more about BB codes used in this forum, just click on the link below...

    Bulletin Board Codes Tags
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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