PC Review


Reply
Thread Tools Rate Thread

Cutting down code

 
 
Aidan
Guest
Posts: n/a
 
      16th Oct 2009
I have recorded a macro to print the same range on a series of sheets and
then return to first worksheet. Is there a way of cutting down on repetition
in code. Please see example of what I have...

Range("B328:L347").Select
ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
Selection.PrintOut Copies:=1
ActiveSheet.Next.Select
ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
Selection.PrintOut Copies:=1
ActiveSheet.Next.Select
Range("B328:L347").Select
ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"

Thanks in advance, Aidan.

 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      16th Oct 2009
Hi,

Not tested but looks OK. Change the line
S = "Sheet1,Sheet2,Sheet3"
to the sheet names that you want this to work on


Sub Sonic()
Dim R As Range
Dim V As Variant
Dim S As String
Dim sh As Worksheet
S = "Sheet1,Sheet2,Sheet3"
V = Split(S, ",")
For Each sh In ThisWorkbook.Worksheets
If Not IsError(Application.Match(CStr(sh.Name), V, 0)) Then
sh.PageSetup.PrintArea = "$B$328:$L$347"
sh.PrintOut Copies:=1
End If
Next sh

End Sub

Mike

"Aidan" wrote:

> I have recorded a macro to print the same range on a series of sheets and
> then return to first worksheet. Is there a way of cutting down on repetition
> in code. Please see example of what I have...
>
> Range("B328:L347").Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
> Selection.PrintOut Copies:=1
> ActiveSheet.Next.Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
> Selection.PrintOut Copies:=1
> ActiveSheet.Next.Select
> Range("B328:L347").Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
>
> Thanks in advance, Aidan.
>

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      16th Oct 2009
'for specified sheets
Sub Macro1()
Dim strSheets As String, arrSheets As Variant, intCount As Integer
strSheets = "Sheet2,Sheet3"
arrSheets = Split(strSheets, ",")
For intCount = 0 To UBound(arrSheets)
Sheets(arrSheets(intCount)).Range("$B$328:$L$347").PrintOut Copies:=1
Next
End Sub


'if for all sheets
Sub Macro2()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Range("$B$328:$L$347").PrintOut Copies:=1
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Aidan" wrote:

> I have recorded a macro to print the same range on a series of sheets and
> then return to first worksheet. Is there a way of cutting down on repetition
> in code. Please see example of what I have...
>
> Range("B328:L347").Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
> Selection.PrintOut Copies:=1
> ActiveSheet.Next.Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
> Selection.PrintOut Copies:=1
> ActiveSheet.Next.Select
> Range("B328:L347").Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
>
> Thanks in advance, Aidan.
>

 
Reply With Quote
 
Aidan
Guest
Posts: n/a
 
      16th Oct 2009
Thanks Mike, I'll give it a go.

"Aidan" wrote:

> I have recorded a macro to print the same range on a series of sheets and
> then return to first worksheet. Is there a way of cutting down on repetition
> in code. Please see example of what I have...
>
> Range("B328:L347").Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
> Selection.PrintOut Copies:=1
> ActiveSheet.Next.Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
> Selection.PrintOut Copies:=1
> ActiveSheet.Next.Select
> Range("B328:L347").Select
> ActiveSheet.PageSetup.PrintArea = "$B$328:$L$347"
>
> Thanks in advance, Aidan.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: PC cutting out philo Windows XP Hardware 1 28th Oct 2008 12:20 PM
Cutting every other row from a spreadsheet =?Utf-8?B?amM0MA==?= Microsoft Excel Misc 3 31st May 2006 08:04 AM
Cutting down someone's name Russell Farr Microsoft Access VBA Modules 9 4th Feb 2004 02:44 PM
Why does I.E. keep cutting out? Andrea Windows XP Internet Explorer 1 10th Sep 2003 04:43 PM
cutting off lacylady42 Windows XP General 1 13th Jul 2003 03:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:14 AM.