Loop and print

jgalas

Board Regular
Joined
Jul 4, 2011
Messages
111
Office Version
  1. 2013
Platform
  1. Windows
Hi,

i want to look at range(n19:n50) if they contain TRUE take the number in range (L19:L50) put in Sheets("Impressao").Range("BF2") and print Sheets("Impressao").
I figured the code for one:

Code:
If Sheets("Dados").Range("n19") = True Then Sheets("Impressao").Range("BF2") = 1
      Sheets("Impressao").PrintOut
If Sheets("Dados").Range("n20") = True Then Sheets("Impressao").Range("BF2") = 2
      Sheets("Impressao").PrintOut
If Sheets("Dados").Range("n21") = True Then Sheets("Impressao").Range("BF2") = 3
      Sheets("Impressao").PrintOut
......
I could copy this code 31 times.... but it will be simple to use a loop a think. At the moment i dont know how to do it, if anyone can help me it will save me hours of works.

Thanks for your help
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi jgalas,

Let me know how this goes:

Code:
Option Explicit
Sub Macro1()

    'http://www.mrexcel.com/forum/showthread.php?t=578642

    Dim rngCell As Range
        
    Application.ScreenUpdating = False
    
    For Each rngCell In Sheets("Dados").Range("N19:N50")
        If rngCell.Value = True Then
            With Sheets("Impressao")
                .Range("BF2").Value = rngCell.Offset(0, -2).Value
                .PrintOut
            End With
        End If
    Next rngCell
    
    Application.ScreenUpdating = True

End Sub

HTH

Robert
 
Upvote 0
Is exactly what i wanted you save me a lot of hours working.
Thanks a lot Trebor.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

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