Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Page Dependent On Code



This is a piece of simple code I have in a macro at the moment -


Code:
--------------------
If Application.Sum(Range("L6")) 0 Then
Application.ActivePrinter = "\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on Ne04:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on Ne04:", Collate:=True
End If

--------------------


I need to change this code so that it loops around in some way.

The cell the code is currently looking at ("L6") needs to change to
("N6").

It needs to look at N6 in Sheets - Bic_Code01 then Bic_Code02 etc up to
Bic Code_20.

If ("N6") is equal to one of the following codes on any of these sheets
-

ABA
AB
AC
ACQ
WH
A
ACX
AKLP
AGB
ABQ
AKC
AVGM
ABC
APF
AFPC
ACV
AFY
JFH
AFC
AFF

Print the Page if not move to the next sheet, look at N6 and repeat the
process.

So basically look at N6 on every sheet in the workbook and if it equals
any of the codes print the page.

I have to do this for 28 files all with 20 sheets in all with different
codes.

There won't always be 20 codes there might be just six so stop after
the last code.

Any help much appreciated.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110050

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Print Page Dependent On Code


Hi Timbo

This should do it. I have just entered some codes as an example, it should
be easy to add all

Sub PrintSomeSheets()
Dim PrintCodes As Variant
Dim PrintPage As Boolean
PrintCodes = Split("ABA,AB,AC,ACQ,WH,A,ACX", ",") ' Here goes all codes
Application.ActivePrinter = "\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on
Ne04:"

For Each sh In ActiveWorkbook.Sheets
For c = LBound(PrintCodes) To UBound(PrintCodes)
If PrintCodes(c) = sh.Range("N6") Then
PrintPage = True
Exit For
End If
Next
If PrintPage = True Then
sh.PrintOut Copies:=1, ActivePrinter:= _
"\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on Ne04:",
Collate:=True
End If
PrintPage = False
Next
End Sub

Best regards,
Per

"Timbo" skrev i meddelelsen
...

This is a piece of simple code I have in a macro at the moment -


Code:
--------------------
If Application.Sum(Range("L6")) 0 Then
Application.ActivePrinter = "\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on
Ne04:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on Ne04:", Collate:=True
End If

--------------------


I need to change this code so that it loops around in some way.

The cell the code is currently looking at ("L6") needs to change to
("N6").

It needs to look at N6 in Sheets - Bic_Code01 then Bic_Code02 etc up to
Bic Code_20.

If ("N6") is equal to one of the following codes on any of these sheets
-

ABA
AB
AC
ACQ
WH
A
ACX
AKLP
AGB
ABQ
AKC
AVGM
ABC
APF
AFPC
ACV
AFY
JFH
AFC
AFF

Print the Page if not move to the next sheet, look at N6 and repeat the
process.

So basically look at N6 on every sheet in the workbook and if it equals
any of the codes print the page.

I have to do this for 28 files all with 20 sheets in all with different
codes.

There won't always be 20 codes there might be just six so stop after
the last code.

Any help much appreciated.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=110050


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Page Dependent On Code



The code your provided yesterday works a treat many thanks. Is it
possible to change this part of the code


Code:
--------------------
If PrintCodes(c) = sh.Range("N6") Then
--------------------


to this


Code:
--------------------
If PrintCodes(c) = sh.Range("N:N") Then
--------------------


?

My reason for asking is that I have found that on a minority of the
worksheets the code is appearing further down the worksheet not in a
specific cell.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110050

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Print Page Dependent On Code


Thanks for your reply.

You have to test the column cell by cell.

For each cell In sh.columns("N")
if cell.value=PrintCodes(c) then
PrintPage = True
Exit For
End If
Next

But there are other options...

If PrintCodeCell is the only or downmost cell in the column, you can use
this:

if PrintCodes(c)=sh.Range("N" & Rows.Count).End(xlup) then

or you use excel 2007, you can name each print code cell as "PrintCode" and
set the scope to the sheet.

Then you can use this:

If PrintCodes(c)=sh.Range("PrintCode") then

Regards,
Per


"Timbo" skrev i meddelelsen
...

The code your provided yesterday works a treat many thanks. Is it
possible to change this part of the code


Code:
--------------------
If PrintCodes(c) = sh.Range("N6") Then
--------------------


to this


Code:
--------------------
If PrintCodes(c) = sh.Range("N:N") Then
--------------------


?

My reason for asking is that I have found that on a minority of the
worksheets the code is appearing further down the worksheet not in a
specific cell.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=110050


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Print Page Dependent On Code



I want to find the code which will be in column N anywhere N6 and N200,
which would be the best option for that? I don't have access to Excel
2007.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110050



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Print Page Dependent On Code


Hi Timbo

You could loop through the cells as I suggested in my last post or you can
use Find, which I think is more efficient...

Sub PrintSomeSheets()
Dim PrintCodes As Variant
Dim PrintPage As Boolean
Dim CodeRange As Range
Dim Found As Variant

PrintCodes = Split("ABA,AB,AC,ACQ,WH,A,ACX", ",") ' Here goes all codes
Application.ActivePrinter = "\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on
Ne04:"

For Each sh In ActiveWorkbook.Sheets
Set CodeRange = sh.Range("N6:N200")
For c = LBound(PrintCodes) To UBound(PrintCodes)
Set Found = CodeRange.Find(what:=PrintCodes(c),
After:=sh.Range("N200"), Lookat:=xlWhole)
If Not Found Is Nothing Then
PrintPage = True
Exit For
End If
Next
If PrintPage = True Then
sh.PrintOut Copies:=1, ActivePrinter:= _
"\\bristol\Canon CLC4040-H1 PS Ver1.0 2 on Ne04:",
Collate:=True
End If
PrintPage = False
Next
End Sub

Regards,
Per

"Timbo" skrev i meddelelsen
...

I want to find the code which will be in column N anywhere N6 and N200,
which would be the best option for that? I don't have access to Excel
2007.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread:
http://www.thecodecage.com/forumz/sh...d.php?t=110050


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dependent page items in pivot table TC Excel Discussion (Misc queries) 3 October 30th 09 01:00 AM
Trace Dependent - off worksheet page reference happy 111 Excel Discussion (Misc queries) 1 November 25th 07 10:51 AM
Setting the print area in page set up to print 1 page wide by 2 pages tall EA[_2_] Excel Discussion (Misc queries) 2 July 12th 07 08:39 PM
print macro dependent on conditional format mwam423 Excel Programming 4 July 6th 07 06:22 PM
Vb code to print a page # Felice[_2_] Excel Programming 1 October 18th 03 03:10 PM


All times are GMT +1. The time now is 01:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"