VBA Code For Printing Variable Print Ranges
May 5, 2009
I am trying to write VBA code that will print a print range that is presented in cell F3 on a "Reports" worksheet. The content of F3 will change depending on how many reports the user selects to print. For example, he could select one, two, three reports etc - up to twelve. The cell ranges of each report are named (e.g. Report1, Report2 etc) so that if the user selects to print Reports 1 and 2, the contents of cell F3 are "Report1,Report2". If I replace WhatToPrint with "Report1,Report2" the print macro works.
Sub Macro2()
Dim WhatToPrint As String
WhatToPrint = Sheets("Reports").Cells(3, 6).Value
'sets the variable to equal the contents of cell D3 which contains the formula
'summarising the print ranges I want to print
Sheets("Reports").Cells(3, 6).Select
ActiveCell.FormulaR1C1 = WhatToPrint
' pastes the variable in cell F3 - just to check that it looks like I want it to
Sheets("Reports").PageSetup.PrintArea = WhatToPrint
'uses the variable to set print area - this is where it fails!
'if you replace the variable with the contents of cell F3 the macro will work
ActiveWindow.SelectedSheets.PrintPreview
End Sub
View 3 Replies
ADVERTISEMENT
Apr 27, 2009
I want to have code that will print everything down the sheet until it sees a blank in column A. I have included the code i am trying but it keeps giving me errors.
View 3 Replies
View Related
Nov 7, 2009
On the attached sheet I would like to set the print range and then print based on 1 cell's valve. F9 is the value I would like to use:
If F9=1 I need it to print A1:M43
If F9=2 I need it to print A1:M87
If F9=3 I need it to print A1:M131 and so on.
View 3 Replies
View Related
Apr 11, 2008
I have a report that is generated from a manufacturing process that looks like the example below. the report is 40 pages long when all the data is printed. i am looking for a way to only print this range if a dimension is "out of tolerance". if the dimension is within tolerance, there is always the "garbage" text of plus and minus. if every row is "within tolerance" in the range the cells in the OutTol column would all contain the "garbage" text but it will not always be identical. so, in summary, actual OutTol values = print and all "garbage" = not printed.
NomActDevLoTolUpTolOutTol
Y-0.956-0.9480.008-0.0030.0030.005
Z-1.413-1.4130.000-0.0030.003---*|++++
DIA0.4220.4240.002-0.0030.006----|+*++
POS0.0160.0110.005
View 9 Replies
View Related
Sep 24, 2013
I've found some code which works to print certain pages with value in cell A1 but I need to print dynamic ranges on some of the sheets as they will have filters on so the rows ranges will be different each time.
So far this is what I have but the dynamic range part is not working:
VB:
Sub Print_All_Worksheets_With_Value_In_A1()
Dim Sh As Worksheet
Dim Arr() As String
Dim N As Integer
[Code] ....
View 3 Replies
View Related
Apr 15, 2009
I am trying to come up with a way to print out data that is variable in the amount of rows to print.
1. Cells C1 thru M6 is heading of report
2. Cells C7 thru M400 all have formulas and display information only when criteria in Column C in each row is met, if condition is not met it displays no informtion. (There lies my problem).
I need a way to print out only the area that information is displayed in and skip the areas that are not displayed. (Currently I have hard coded the print range using the largest report)
View 6 Replies
View Related
Jan 30, 2009
I am after a code that will sort out the below printing problem
I want excel to hide ALL OF column E from the printer, i want to see the information myself but when i press print, column E will not show on my printed page
i have found this
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
.Range("e1").EntireColumn.Hidden = True
.PrintOut
.Range("e1").EntireColumn.Hidden = False
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
but am not sure how to enter it, also if the code is correct. I have entered it using the alt+f11 then clicked on this sheet, and put it in there but it still dont work
View 9 Replies
View Related
Mar 22, 2007
I have to print this Excel in the following manner.
I have a table which is similar to one given below. All I need is to print these information in each sheet. For Example Coat sold by CA separately, Coat sold by FD separately, and so on (like the lines I have entered).
Is there any way I can create a Macro for this....
CoatCA420
CoatCA420
CoatCA420
----------------------
CoatFD420
CoatFD420
CoatFD420
CoatFD420
CoatFD420
----------------------
CoatKS420
----------------------
Any usual information will be highly appreciated... FYI.. I am new to Excel VBA programming.
View 5 Replies
View Related
Feb 19, 2008
I'd like to set the print range based on the last row with text in specific columns. I found a couple of macros in this forum to adapt, but neither are working. Extra rows, which only contain conditional formatting, and other excluded rows and columns still print.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim MaxRow As Long, i As Integer
MaxRow = 1
For i = 1 To 6
Cells(65536, i).End(xlUp).Select
MaxRow = Application.WorksheetFunction.Max(MaxRow, ActiveCell.Row)
Next i
ActiveSheet.PageSetup.PrintArea = "$A$2:$F$" & MaxRow
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim LastRow As Long
LastRow = ActiveSheet.Columns("A:F"). Find(What:="*" _
, After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ActiveSheet.PageSetup.PrintArea = "$A$2:$F$" & LastRow
End Sub
View 4 Replies
View Related
Apr 19, 2008
In a previous, expired thread, the following code was suggested as a way to capture the page-setup zoom value after setting PagesTall and PagesWide. It works fine when single-stepping in the VB Editor and when run directly by the user, via a button click or Tools=>Macros...=>Run, but fails when run under a Worksheet_Activate() event call.
Does anyone understand why that is and/or have a fix or workaround?
Sub X()
'
Application.ExecuteExcel4Macro "PAGE.SETUP(,,,,,,,,,,,,{1,#N/A})"
Application.ExecuteExcel4Macro "PAGE.SETUP(,,,,,,,,,,,,{#N/A,#N/A})"
MsgBox "Zoom factor is " & ActiveSheet.PageSetup.Zoom
End Sub
View 3 Replies
View Related
Sep 10, 2008
I have created a sheet to calculate a resturant bill that need to be printed for each customer. I am trying to creat a command that will print the sheet up to the last item in the bill "sheet2". So I need the printin area to change according to the number of itmes.
View 14 Replies
View Related
Jun 10, 2006
I've created a Small Program to print envelps and everything is ok. My request is how to print all Itemes by one button (printall).
View 2 Replies
View Related
Jun 22, 2006
I have this macro
For I = 6 To 18
Sheets(I).Visible = xlSheetVisible
PrintSubs Sheets(I)
Sheets(I).Visible = xlSheetVeryHidden
Next
End Sub
When it starts printing it starts off with my "JOBCOM" sheet which is sheet20. why it would start printing with that one. That sheet shouldn't even print at all. It's only supposed to print sheets6 to sheet18.
View 9 Replies
View Related
May 9, 2007
We have a program that sorts Characters into separate racks. I need to print a label for each rack. I can set the print area to cover the whole rack area but what I do not want to do is print blank labels. As you can see I have blank labels at the end of the row, and occasionally there will be one in the middle of the row as well. I have attached a screen shot of the list that I need to print. Is there any way that I can set the printer to only print the label that does have information on it? or am i going to have to print the blank labels in the middle as well?
View 2 Replies
View Related
Aug 17, 2007
I've seen code to set the print area for a dynamic range. However, how can the print area be defined by these parameters:
A1 to one extra blank row below the last cell of data in column A (height), and
last column with data in row 12 (width).
Here is what I'm starting with...
Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet. Names.Add Name:="Print_Area", _
RefersTo:=Range(Range("A1"), _
Range("A1:IV65536"). Find(what:="*", searchorder:=xlByRows, searchdirection:=xlPrevious, after:=Range("A1")))
End Sub
I have copied formulas in other columns down beyond what the last row of col. A will be. Also, this will need to be applied to about 7 sheets in one book.
View 4 Replies
View Related
Aug 11, 2006
I am trying to print non continuous ranges of data in the same worksheet using the print area - by keeping the ctrl button pressed etc... it works fine but the outcome is that the text in the pages becomes very smaller when compared to when you print page by page and fit every page to one.
View 2 Replies
View Related
Oct 17, 2013
I have been trying to see if I can set up a single (A1) print button to create a selection box to select a name range and than print that range, but have been unable to figure out how to accomplish it. I have 26 name ranges called PP01 thru PP26 and I want to be able to select the range before printing.
View 1 Replies
View Related
Apr 2, 2007
I used the macro recorder to take selected cells from a worksheet and automaically print the selected area. It works great - but i (as usual) want it do more - more specifically, i want it to print, say 10 rows, from any row i select.
The worksheet is a live schedule which is updated constantly as production works through the scheduled orders. I want to identify the row which has the current running production order and print that row and the next ten.
how to use the input box to ask for the row # but don't know how to code the actual passing of that variable. I figure i can then marry my existing code to make a working frankensteinish macro.
View 4 Replies
View Related
Apr 9, 2007
I have four sheets workbook, and i'd like to set a command button that prints scattered tables ( ranges) on my workbook but still have a pattern.
I attached a simple wokbook that explains how ranges are positioned in my workbook, i hope that it is possible to print these tables in the sequence shown in the file by a single command.
View 5 Replies
View Related
Apr 13, 2007
I am trying to create a primitive counter. My idea is to write a value to a file, read it, add one and write it back. The file as a single value tab-delimted of 5000. The code below produces the odd output on debug. I really cant understand it.
Public Function nextInv() As Integer
Dim fname As String
Dim fnum As Integer
Dim stringArray()
Dim invNum As Integer
fnum = FreeFile()
fname = "nextInv.txt"
stringArray() = parse(OpenRecordClassesFn(fname), vbTab)
For i = UBound(stringArray) + 1 To LBound(stringArray)
invNum = stringArray(i)
Next
If FileExists(fname) Then
Open fname For Output As #fnum
End If
invNum = invNum + 1
Debug.Print "invNum"
Print #fnum, (invNum & vbTab)
Close #fnum
invNum = invNum + 1
End Function
Public Sub testHarness()
Debug.Print nextInv()
End Sub
with a output of
5000
invNum
0
and the value in the file of 1. It should be 5001.
View 9 Replies
View Related
Jan 6, 2008
I have a multitude of reports to work on. Right now, the headers are made manually using the first few rows of each sheet, which is very inefficient, and difficult to get them to look the same. If the sheet is put on "Fit to X pages", the header is shrunk still. The reason this is done is because in the header / footer section of Excel 2002/2003, you can only use static text and predefined footer data (pg 1 of X, date, etc). Basically, I'd like to use a header that stays the same size, format, look between sheets/workbooks, but can accept variables in some way.
View 7 Replies
View Related
Feb 14, 2007
I export data from another programme into excel and have written a macro to move and format this. The number of rows of data exported will be different each time. I need to be able to print this data and want to add it to the macro. I have learnt to use this code to select this data working from the last used cell to the top
Range("a1:d1", Range("a65536:d65536").End(xlUp)).Select
Using the macro recorder for printing one of my exports I got this code
Range("A1:D53").Select
Range("D53").Activate
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup.......................
View 5 Replies
View Related
Aug 30, 2013
She has a spreadsheet created in Excel 2003 (she is still using 2003) which contains an image with a textbox in the top left corner then all other cells contain data.
When user prints this spreadsheet all that prints is the image and the textbox.
I have cleared the print area reset the print area removed the picture (prints only the text box)
and none of these changes have changed what prints.
I have checked all printer setting and these appear normal.
previously user could print this spreadsheet fine and all other worksheets in the workbook print fine as well.
other users are still able to print to the same printer correctly from this spreadsheet.
View 2 Replies
View Related
Apr 28, 2013
I am using Excel 2010
I have over 800+ pages of chart that only takes up 6 columns and around like 9000+ rows.
I wanted to print this chart on paper and need hardcopies. However, the chart in its current setup prints only on the left half of the page leaving the right half empty.
How do i make use of the full space properly? Each chart has a "page number" on it so I want the chart to print continuously from one half of the page onto the next half and then the second page, third, etc.
Here is a visual demonstration of how things currently are and how i'd like to get them to be:
As you can see, This is the first of many charts and its numbered Page 9 and next one is page 10.
Pic1
How this looks when i try to print, it's only on the left side. right is all blank
Pic2
How i want it to look like upon printing
Pic3
As you can see in the last picture, once page 14 chart has no space it automatically continues chart on right side of page and then moves on to print rest.
[URL]
View 7 Replies
View Related
May 19, 2014
I have a number defined print ranges. I wish to create a list of all the named print ranges and then select certain ranges to print in a single document. I have been told can use something called a "userform".
View 4 Replies
View Related
Sep 14, 2006
I am trying to create a simple code that will allow me to print a range that will change according to the initial inputs. The columns will never change, however the rows will.
So far I have:
Sub PrintLog()
Dim Printer As Range
Set Printer = ActiveSheet.Range("a9", Range("e65536").End(xlUp))
Printer
End Sub
View 4 Replies
View Related
Feb 16, 2007
I want to create a very simple macro to print some ranges that I have defined in my workbook. The ranges are as follows:
Note: Each of these ranges is in a different worksheet named Cons_Summ, Esky_Summ, Indy_Summ, and Gfld_Summ respectively.
To be printed in portrait view:
- Cons_Summ_IS
- Esky_Summ_IS
- Indy_Summ_IS
- Gfld_Summ_IS
To be printed in landscape view:
- Cons_Summ_OH
- Esky_Summ_OH
- Indy_Summ_OH
- Gfld_Summ_OH
I just want to create a macro so I can run it and it will print all of the ranges listed above with the proper orientation. Nothing special, each range must fit on 1 page x 1 page.
View 7 Replies
View Related
Aug 24, 2007
with creating vb code that will select certain rows in a spreadsheet, set the print area to those rows and print them out, and then reset the print area back to default.
The data is all on one sheet, but is split into 5 different areas, each below the next, with the column headers at the top of each.
e.g.
header_____header_____header
data_______data_______data
data_______data_______data
data_______data_______data
header_____header_____header
data_______data_______data
data_______data_______data
data_______data_______data
and so on. At the press of a button it'll set the print area to the first section and print (the section includes the headers as well as the data). Then at the press of another button it'll set the print area to the next section. There could be any amount of rows of data in each section so it needs to cope with that.
View 9 Replies
View Related
Dec 28, 2009
What is the best way to declare non contiguos print ranges?
For instance I have the following
Sheets("Report").Range("C17:C33").Copy
But I want to add other print ranges like J5:K5
View 9 Replies
View Related
Jan 6, 2009
I am using excel 2000
From this and other forums I have found and adapted 2 bits of code as follows
The code below is used to print the sheets in a workbook in reverse order eg sheet 78, sheet 77, sheet 76 etc.....
View 14 Replies
View Related