Require Loop to work till last row with same criteria

Navi_G

Board Regular
Joined
May 30, 2018
Messages
94
Office Version
  1. 2016
Platform
  1. Windows
Hi Experts,
I have a master sheet in a workbook in which I made a button of print all. I want to run the code of print all button for count one to last row and print one by one. Link of my file is bellow:
Coupon Sheet.xlsm
VBA Code to Print all button is:



VBA Code:
Sub Rectangle3_Click()
Dim x As Long
x = 1
For counter = 1 To 3

Range("A1").Value = x
x = x + 1
ActiveSheet.PrintOut

Next counter

End Sub

Thanking you in anticipation.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
This might be a bit too basic but might get you started.

VBA Code:
Sub Rectangle3_Click()
    Dim rowList As Long
    Dim wsNameList As Worksheet
    Dim strName As String
    Dim wsToPrint As Worksheet
    
    Set wsNameList = Worksheets("Name List")
    
    rowList = 2
    strName = wsNameList.Range("B" & rowList).Value
    
    Do While strName <> ""
              
        Set wsToPrint = Worksheets(strName)
        wsToPrint.PrintOut
    
        rowList = rowList + 1
        strName = wsNameList.Range("B" & rowList).Value
    Loop

End Sub
 
Upvote 0
This might be a bit too basic but might get you started.

VBA Code:
Sub Rectangle3_Click()
    Dim rowList As Long
    Dim wsNameList As Worksheet
    Dim strName As String
    Dim wsToPrint As Worksheet
   
    Set wsNameList = Worksheets("Name List")
   
    rowList = 2
    strName = wsNameList.Range("B" & rowList).Value
   
    Do While strName <> ""
             
        Set wsToPrint = Worksheets(strName)
        wsToPrint.PrintOut
   
        rowList = rowList + 1
        strName = wsNameList.Range("B" & rowList).Value
    Loop

End Sub
Dear Sir,
I might be unable to make you understand that what i am saying and what i want actually in my workbook there are many work sheets but i want to link this code with bundling report only. I want that this code could count SR# from bundling report in "A1" of master sheet. to gain Cut, Bundle, QTY, Size i use VLOOKUP VBA code should count serial # in A1 of Master sheet 1 by 1 till last row of bundling report and also take print of range "B2:M72". I attached link again plz provide help accordingly.

Coupon Sheet.xlsm
 
Upvote 0
See if this is what you had in mind.

Your print area is currently B1:M49, and I am not sure that B2:M72 makes sense especially if you want it to print on one page.
I have put the PageSetup line in so its ready for you to use but have commented out pending you figuring out what range you want to print.

VBA Code:
Sub Rectangle3_Click()
    Application.EnableEvents = False
    
    Dim rowList As Long
    Dim wsBundling As Worksheet
    Dim strSRNo As String
    Dim wsMaster As Worksheet
    Dim MasterSR As Range
    
    Set wsBundling = Worksheets("Bundling Report")
    Set wsMaster = Worksheets("Master Sheet")
    Set MasterSR = wsMaster.Range("A1")
    'wsMaster.PageSetup.PrintArea = "$B$2:$M$72"
    
    rowList = 2
    strSRNo = wsBundling.Range("A" & rowList).Value
    
    Do While strSRNo <> ""
        MasterSR.Value = Val(strSRNo)
        wsMaster.PrintOut
        
        rowList = rowList + 1
        strSRNo = wsBundling.Range("A" & rowList).Value

    Loop
    
    Application.EnableEvents = True
End Sub
 
Upvote 0
Solution
Dear Sir,
Thanks for your amazing code.

Regards,
Navi_G
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

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