VBA - Print until criteria is met

Bajjonetaz

New Member
Joined
Sep 25, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Im looking for help in creating a VBA for this excelfile.

I want to with a quick command run a print of all items in the "data" sheet, up until a empty row appears.
So it would print 1,2,3,4 etc until the empty cell popups.

In the case attached would be cell "B21"

Can someone assist?
 

Attachments

  • 2023-09-25_225433.png
    2023-09-25_225433.png
    55.7 KB · Views: 10
  • 2023-09-25_225415.png
    2023-09-25_225415.png
    28.6 KB · Views: 10

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi @Bajjonetaz . Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

Set the name of your sheet to print in this line of the macro:
Rich (BB code):
With Sheets("printsheet")

Put the following macro in a module.
VBA Code:
Sub MacroToPrint()
  Dim i As Long
  Dim shD As Worksheet
 
  Set shD = Sheets("Data")
 
  For i = 2 To shD.Range("B:B").Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
    With Sheets("printsheet")    'Fit the name of your sheet to print
      .Range("I3").Value = shD.Range("A" & i).Value
      .PrintOut
    End With
  Next
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
 
Upvote 1
Solution
@DanteAmor Thanks for the quick help, it worked amazingly!

is there someway we can put a delay of maybe 5sec between each print, because the QR codes didn't have time to re-generate between each print
 
Upvote 0
Solved it :)
Inserted this in the code
Application.Wait (Now + TimeValue("0:00:10"))

Thanks for your assistance
 
Upvote 0
Im glad to help you.

The MrExcel community enjoys helping, now there is an option to mark the answer as a solution, marking it to the right of the post..

1675010248462.png


Please, If my answer helped you, click like and do not forget to mark my post as a solution.

Thanks
Dante Amor
 
Upvote 1
Hi again!
The googleapi that I was using to create QR codes inbetween prints, that service has now been shutdown.

So Ive changed from using a macro to the =image() function to retrieve the QR code. But because of this change the printsheet macro no longer supports the change of QR code inbetween the change of rows to print.
How can I change that the printsheet macro recognizes and updates the =image() function through the I3 cell inbetween prints?

Any ideas?
 
Upvote 0
Hi @Bajjonetaz, I hope you are well..

How can I change that the printsheet macro recognizes and updates the =image() function through the I3 cell inbetween prints?
I don't know how you have that image.
It seems to me that it is a different topic than the original post, I recommend that you create a new thread and include all possible information about your image, if possible share your file and paste the link in the new thread.
That way you can get more help from different people.

🧙‍♂️
 
Upvote 1

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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