How to stop my print Macro if a cell contains nothing.

Wagsbags83

New Member
Joined
Apr 21, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Good Morning All,

I am really somewhat new with using macro's and VBA in excel sheets.

Currently I have a macro that I recorded that looks like the following.

Sub PrintAttempt()
'
' PrintAttempt Macro
' Print Labels
'

'
ActiveCell.FormulaR1C1 = "1"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
ActiveCell.FormulaR1C1 = "2"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
ActiveCell.FormulaR1C1 = "3"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
ActiveCell.FormulaR1C1 = "4"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
ActiveCell.FormulaR1C1 = "5"
Range("B3").Select
End Sub

Basically this enters the number 1 in cell B1 which then pulls a bunch of information from the sheet Database and prints. Then replaces 1 with 2 and pulls that info and prints.

I am trying to figure out how to get the macro to stop when it reaches a number that pulls no information.

Any help would be greatly appreciated.

Thanks,
Chris
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
VBA Code:
Sub PrintAttempt()
     For i = 1 To 100
          ActiveCell.FormulaR1C1 = i
          If Range("C1") = "" Then Exit For     'somewhere a cell where, if you change the activecell, the loop has to stop as soon as that one is empty
          ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
     Next
End Sub
please, for easier read, copy&paste,..., use the VBA-icon in the ribbon here above, and copy your code in between.
 
Upvote 0
Hey BSALV,

Thanks for the tip there at the bottom. I apologize as I am new to the Forum but appreciate any advice at all.

As for the code provided for the macro, I can not thank you enough. This worked perfectly and is a huge huge help !!!

Thanks again truly truly appreciate you.

Chris
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,017
Members
452,542
Latest member
Bricklin

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