macro to print selection when there is data in rows

bh24524

Active Member
Joined
Dec 11, 2008
Messages
319
Office Version
  1. 2021
  2. 2007
Hi, so I have a sheet that does lookups to other tabs and displays data when someone is changing a schedule.
Here is a simplified format:

1697208257308.png


What we have to do is print out one sheet per person that is actually changing schedules so that each printed sheet displays the headers and only that persons name and the rest of the info printed to column H. For this sample we only go to column H for printing but what is in column I and beyond wouldn't get printed. What I currently do is hold down the ctrl button and then select from A to G those changing schedules and when I go to print it, it has each person separated on their own sheet and I print 2 copies. So base don the above sample data, I would have 3 separate pages - one for John Smith 1, one for John Smith 5, and one for John Smith 8.

My question is instead of me having to ctrl highlight the different selections I want to print is if there is a macro that could do this for me, so basically if columns F thru H have some type of data populating in them, it would print from A to H. So if I ran the macro according to the above screenshot sample, I would expect to see 3 separate pages:
Page 1
1697208851349.png


Page 2
1697208871124.png


Page 3
1697208890145.png

Again, printing excludes anything beyond column H.
 

Attachments

  • 1697207768823.png
    1697207768823.png
    27.7 KB · Views: 4
  • 1697208388083.png
    1697208388083.png
    5.7 KB · Views: 5
  • 1697208443036.png
    1697208443036.png
    6.3 KB · Views: 4
  • 1697208462288.png
    1697208462288.png
    6.2 KB · Views: 4
I should have anticipated something like that maybe.
Anyway, a lesson learned.
Let us know how it works after the changes.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Success! Just one thing though, can we get the code to actually print two copies?
 
Upvote 0
I think I figured it out, I brought up the intellisense and saw the fields so I did this:

Range("A1").Resize(lr, 18).PrintOut , , 2

Going to test that...

Success! I hope I can get to this skill level one day but I have a ways to go. Thank you very much for your help and patience!
 
Last edited:
Upvote 0
Just since the code had undergone a few revisions, posting it in its final form:

VBA Code:
Option Explicit

Sub Print_All_Bid_Changes()
Dim lr As Long, i As Long, j As Long, dataArr, arr
lr = Range("A:A").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
dataArr = Range("A5:D" & lr).Value
    For i = LBound(dataArr) To UBound(dataArr)
        If dataArr(i, 1) <> dataArr(i, 2) Then arr = arr & "|" & dataArr(i, 4)
    Next i
  
    arr = Split(Mid(arr, 2), "|")
    Application.ScreenUpdating = False

    'You can delete the next 6 lines if not needed although they don't do any harm
    With Worksheets("MOVES").PageSetup    '<---- Change Sheet Name
        .Zoom = False
        .Orientation = xlLandscape
        .FitToPagesTall = 1
        .FitToPagesWide = 1
    End With
  
    For j = LBound(arr) To UBound(arr)
        With ActiveSheet.Range("A4:H" & lr)
            .AutoFilter 4, arr(j), xlFilterValues
            Range("A1").Resize(lr, 18).PrintOut , , 2  '<----- The number 18 is Column R
            .AutoFilter
        End With
    Next j
Application.ScreenUpdating = True
End Sub

Also, thank you as well NateSC. Although I didn't end up using the code you had initially provided, I do appreciate the time and effort you put forth into it and did give you a rep score for it! Take care!
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top