Ranges for Print

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The I am still having problems with my macro,
this is a a module within my macro,
************************************************************
Sub PrintCode()
Dim i As Integer, c As Integer, Q As Integer
c = 0

For Q = 2 To 2
With Sheets("MacroData")
B = .Cells(Q, 2).Value
End With


For i = 1 To 10000
With Sheets("Salary etc")
A = Left(.Cells(i, 1), 3)
End With

If A = B Then
With Sheets("MacroData")
c = c + 1
.Cells(i, 5).Value = c

.Cells(i, 7).Value = 1


End With

End If
Next i
With Sheets("MacroData")
D = .Range("G2").Value
E = .Range("H2").Value
End With
With Sheets("Salary etc")
**.Range("A1:R4", D & ":" & E).Select***
.Selection.Print
End With

Next Q
End Sub
************************************************************
The part near the end of the macro highlighted with **.** gets highlighted,
with
select method, range class
the error,

It is very close to being finished.

Many thanks,

Andy
 
You can only select a range on a worksheet that's already selected.

So you could modify your code this way (I wouldn't!):

With Sheets("Salary etc")
.Select
.Range("A1:R4", D & ":" & E).Select
.Selection.Printout
End With

or just print it directly (I would!):

With Sheets("Salary etc")
.Range("A1:R4", D & ":" & E).printout
End With

and I think you meant .printout

I like
.printout preview:=true
for testing purposes.

And multiple ranges will cause multiple sheets of paper to print (each range
starts on its own sheet).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top