VBA Code For Printing
What I want to do is print a specific worksheet from a specific workbook based on data entered in text boxes. One text box would provide the workbook name and the other text box would provide the worksheet within the specified workbook. All the user would have to do is enter the workbook and worksheet names and then press a button to print. I currently have created a separate workbook with just a userform that contains a print button and two text boxes.
View Complete Thread with Replies
Related Forum Messages:
VBA Code To Cancel Printing
I have a code that prepares my spreadsheet and then prints out around 6 different sheets when all is said and done. The prints are not together in the code. I was wondering if there is something that I can add at the beginning of the code to ask the user IF they want a Printout. If they answer Yes then they get printouts of the 6 or so sheets and if they answer No then the code will run but no printouts occur???
I have play3ed around a bit and implemented the following in one of my codes but this one only has 1 sheet that prints out.
'Checks to see if this is a corrected Deposit in which case Depositor probably has a Verification sheet already printed
If Sheets("Input Sheet").CheckBox5 = True Then
Answer = MsgBox("It's seems that this Verification sheet was already printed once. Do the Corrections you have made require you to print another one?" & vbCr & vbCr & "If you reuire the Verification sheet to print again the please click YES otherwise click No.", vbYesNo, "PRINT Out Required???")
If Answer = vbYes Then
ActiveWindow.ScrollColumn = 1.........
Vba Code For Classified Printing
i have in sheet1 the names of the students and their marks and the finall results (pass ; fail ; comp)
i bring this data to the student certificate in sheet2 using lookup so when i change the number in h1 (the referance cell) the data ini the certificate will change , and i can print the certificate for every students put it is hard to change it manualy and print so i made this code that helps me to print the whole certicates by clicking the button
this the -
Dim i As Integer
For i = 1 To 49
Range("h1").Value = i
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
now i need anew code to print only the (pass)results students , and one for the failed students certificates
VBA Code For Printing Variable Print Ranges
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.
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
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
Code For Printing
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.....
Code For Printing Multiple Charts
I have a workbook with a chart on a worksheet called Area Report
There are 10 areas in total A - J, to view a particular area cell I2 is validated to only accept entries A - J which represent the Areas, selecting a particular area updates the chart for that area
Is it possible to have a macro that will print all 10 Area Reports, I tried to do it using the Record Macro function, the code was as follows .......
Code For Printing Particular Rows And Columns
I have a worksheet that I use to track my clients and their meal selections over a five day week. Col A is their name, B is their shift (am or pm) C is their table number, D is whether they will attend that day (yes or no) and E is their meal choice (a b or c) Columns D & E repeat the same information for each day Mon-Fri.
I would like to have a print button so that on a daily basis I can print the clients name and thier meal selection (only those those who have a yes for that day) separating AM shift from PM and then grouping them by their table number rather than alphabetical order.
Suppress Printing With VBA
What i have is over 20 worksheets which have information on them that i want to print when selected so, i have a "main page" with a variety of options for the user to select (by check box) and when they are happy with their selection you would click another check box to print out, i have done this because the printer is set well away from the users and if they printed of sheet by sheet then lots of miles treading back and forth to the printer room would happen so, i thought by doing it this way it would batch print all selected sheets after selection, the code is set up to print all sheets which are selected by "true" in cell O2.
This is no problem as it works well but the code also prints when the check box is de selected. What I would like is a message box to appear before the main macro runs for the user to select "yes or no" to confirm printing. I have put code in this for the command but it will not run the main magro if you select "yes"...below is the code for the main print loop...I think the code for print message should appear before this...
VB Code/Macro Printing With Page End Pulled From Workbook
I have a worksheet that changes in length. There is a formula that calculates how many pages the sheet will be. The also is a print button on the sheet that will print a coversheet "Sheets("Title")" and then it is supposed to print the data on the second sheet. Below the code I have so far... I know I am missing something, but knowing very little about macros I just can't seem to figure it out.
VBA Conditional Page No Printing
I need a code that will print a page only if there is a value in cell G4 for example.
Im think I have part of the code but cant work out the " if " part
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
VBA: Printing Sequential Invoices
I have written some code for a friend of mine, but I cannot test it because I currently don't have a printer attached to this computer. I am confident that it will work, but I would like a second set of eyes to confirm that I havent missed anything.
I have a userform with two textboxes. One of them asks how many copies of the invoice to print out, and the second one asks what invoice number to start with. THe invoice numbers are recorded in Cell I1.
Invisible Text Even When Printing - VBA
I use this code to make text not visible and it does work well using matching font color (fcolor) and cell color (icolor), but this leaves one issue. When I print the text it is no longer hiden by the matching colors.? I was hoping to use -4241 to set the color to no color,(invisible?) but now it produces errors.
Private Sub Worksheet_Calculate()
Dim icolor As Integer, fcolor As Integer, Target As Range, FormulaCells As Range
Set FormulaCells = Range("a4:a104")
For Each Target In FormulaCells
Select Case Target
icolor = 37
fcolor = -4142
icolor = 27
fcolor = -4142
icolor = 35
fcolor = -4142
icolor = 45
fcolor = -4142
Viewing And Printing Selected Worksheets - VBA
I have a workbook containing a number of spreadsheets. Some of the spreadsheets are user inputs. The results of the user inputs drive a number of final reports. The final reports (i.e. spreadsheets) are hidden from the user (I don't want the user to be overwhelmed with so many tabs when they open the excel spreadsheet).
I created on the main input tab spreadsheet the following:
1. Check boxes - so that user can select after making his/her inputs the reports that he/she wants to view or print.
Say there are 4 reports (call them Sheet1, Sheet2, Sheet3, Sheet4 - therefore, 4 check boxes. Through the Format Control, the checkboxes have cell links that yield TRUE (if selected) or FALSE if not selected - linked to cells A1, A2, A3, A4 respectively.
2. Option buttons - one for view and another one for print. Through the Format Control, the View and Print option buttons have cell links to cell A5 yielding 1 for View and 2 for Print.
3. Command button - that will clear the check boxes
I would like to know if there is a way to code in VBA to:
1. Unhide the spreadsheets corresponding to the check boxes if selected;
2. Print the spreadsheets corresponding to the check boxes if selected for printing; and
3. Clear the checked boxes to unchecked if the Command button is clicked.
I'm struggling with coding to perform the above tasks.
Printing / Not Printing Ranges Based On Cell Contents
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.
Printing One Page Grayscale And One Page Color With Code
I have a report that I use and right now I have a command button that prints the report x2. What I would like to do is to have it print one in color and one in grayscale. I could do this I think with two different buttons, but I would like to utilize just one. I tried creating a macro but it did not pick up the fact that I changed the properties to black and white.
VBA Macro Code Needed To Run The Code Contained Within A Cell
I have a macro that, when run, needs to read the contents of cell B5, and run the code that it contains.
Cell B5, for example, would contain the text:
Range("B13").Formula = "SUM(D12:D14)"
I need a macro to "execute this code", as if it were in the macro itself.
I have assigned the above to a variable, but am not sure how to execute it.
the_calc = Range("B5").value
Now, how do I run the_calc ?
Efficient VBA Code Vs Macro Recorder Code
What is the most efficient VBA code for the following macro recorded codes? I wish to write more efficient code versus the lengthy, cumbersome macro recorder code.
1) Macro Recorder Code to Copy One Sheet to Another
2) Macro Recorder Code for Replacement Purposes......................
Display All VBA Code In Code Window (VBE)
When I started using VBA, all the code for each module was shown in the code window. This was a bit cumbersome when looking for one sub in particular. Now when I load VBA, all the Subs and Functions have their own page, and can be selected from the right hand drop down list. This is much easier for entering code, and finding subs. However, it is sometimes useful to see 'the big picture', so how do I swap between the two types of display?
VBA Code To INSERT CODE - GURUS
I have a worksheet named mylist, that I delete, then recreate everytime I run a specific macro. However, I have code in this worksheet that I require, so is there a way for me to insert code to "insert code" on the "re-creation" of the worksheet?
VBA Code- How Do You Get The Code Boxes To Appear In Threads
I have code that inserts columns, inserts formulas, and then copies the formulas to the last row of data. It all works good but for some reason, the columns that are being copied, are being copied past the last row of data. It can always be determined how far down it will be copied. Examples: if the last row of data was row 4, then the formulas would be copied down to row 24, if the last row of data was row 54, then the formulas would be copied down to 254, if the last row of data was row 284, then the formulas would be copied down to 2284. I can not figure out how and wh this is happening, but whatever the last row of actual data is on the spreadsheet, there is a 2 being placed in front of the last row of data and the formulas are being copied down to whatever the last row is with the addition of a 2 in front.
Here is the code for the columns additions, and formulas:
Range("O2").FormulaR1C1 = "=CONCATENATE(RC,""/"",RC,""/"",RC)"
Range("P2").FormulaR1C1 = "=IF((RC=7),LEFT(RC[-2],1),LEFT(RC[-2],2))"
Range("Q2").FormulaR1C1 = "=IF((RC=7),MID(RC[-3],2,2),MID(RC[-3],3,2))"
Range("R2").FormulaR1C1 = "=RIGHT(RC[-4],4)"
Lets take this first one for example:
Range("O2:S2").Copy Range("O2:S2", Range("O2:S2" & Range("A" & Rows.Count).End(xlUp).Row))
If the last row of data was row 54, then columns O:S would have the formulas copied down to row 254.
How can this code be modified so the formulas will not be copied past the last row of data?
How do you get the code boxes to appear in these threads. I do not know how to do this. As you can see, all I did was copy and paste my code in this thread.
Create Macro Code With VBA Code
I'm trying to add buttons to an excel spreadsheet at runtime. Each row in the spreadsheet should have its own buttons. I was able to create and edit them with the ActiveSheet. OLEObjects.Add() function, but after that, when i was trying to create code dynamically to react on the buttons' click events excel crashes (actually it works for one button, but not if my routine for adding a new button and event code is called more than once in a row!)
The code below works if the AddCmdbuttonWithCode() is called once, but crashes if it is called two or more times. Excel tries to restore the document after the crash and the first button and its corresponding click event code is visible and works... but NOT the second button and its event code...
The only way I can create multiple buttons right now is by calling my method once per click, opening the vba editor, changing the parameters for my AddCmdbuttonWithCode() routine and execute it again. After that I have mutliple buttons in different lines which all work fine (so the concept seems to work).
The problem seems to be the insertLine method, since everything seems to work if i leave it out (except for the code generation of course, since this is done by this part of the code :-) ). Is it possible that calling the insertLine Method can't be called multiple times? I don't know... any ideas? Feel free to test my code - it's small, easy to understand and has comments.
'this code calls the method which creates the buttons in specific cells with specific names
Private Sub CommandButton3_Click()
'the first call always works!
AddCmdbuttonWithCode "Edit_111_111_114", 23
'the second one crashes excel
AddCmdbuttonWithCode "Edit_111_111_115", 27
Using VBA To Create VBA Code On The Fly
I have a vba module that reads a value from a txt file and saves that value in a variable called "iniInfo". I want to permanently assign that value programatically by using VBA code to create a Public variable e.g. "PUBLIC CONST conFIg = iniInfo" in my modGlobalVar Module. (Of course, this would only create the code if the "conFig" variable doesn't already exist.)
Distributing VBA Code Changes Via VBA
I have a number of identical workbooks used for data capture within the organisation, and need to continue development as time goes on.
Whenever I make a change to the core Excel functions of the workbooks I simply use a VBA procedure to conduct this change within each of the production workbooks, however I am stumped as to how I can achieve this for changes to the VBA code.
I have made some changes to the code held within one of the modules, and have also modified the form slightly. What I want to be able to do is run a VBA procedure that either updates the production workbooks from a central source, or by importing previously exported code / forms.
Insert Vba Code With Vba
I have a code that needs to be placed on any new worksheets created. All new worksheets are made using VBA code already so they just need to be told to add the code into each new sheet. How do I do this?
I want to print data in certain columns which are B, C, D, G, J, N (including the headings in Row 6). Column G contains the department. I want to be able to change the macro code just to print data relating to the department that I chose (i.e I will customize it). Can anyone help me with some VBA code? Basically it should look at column G first and then print all columns with data in for B,C,D,G,J,N.
I might want to print data contained in columns, B, C,D,G,J,N just relating to Department A (which is in column G). It ignores all other lines relating to Departments B, C, D, E etc. Is this possible? I just want it to print only rows containing data and ignore blank cells.
How Do I Say This In VBA Code
I have a macro that sorts cell values in table AM6:AZ17 in descending order according to the values in AR6:AR17.
Cells in AN6:AN17 contain conditional formatting which gets scrambled during the sort.
What code can I add to the macro the tell Excel to preserve conditional formatting in those cells during the sort?
VBA Code That Records The Changes
I have 2 workbooks Mater and Update. I have a VBA code that compare between the two files column by column and update the Master file according to the Update file ( the code below).
Now my user want to see in a separate worksheet ("changes") only the changes - Date and time of changes at column A , old value at column B and new value at column C ........
Find All, VBA Code
When you're in Excel and go to "Edit" - " Find", there's an option to "Find All" and it pops up a list of all of the cells your search string is in.
Is there an easy way to do this same thing using VBA code?
I tried recording a macro, but the code was just blank.
I know it can be done one by one using a loop, but I was wondering if there was any way to just return the whole list at once?
VBA Code Dump.
I am getting a DUMP on the "ActiveWorkbook.SaveAs Filename:=ThisFile" which is a valid PATH. Is there a Charachter max length required in A1?
ThisFile = "S:AccountingSales" & Range("A1").Value
Converted Into Vba Code
I would like to have a code (VBA) for the below formula so I do not have to protect my worksheet (column B).
The above formula ends down until B13000. I feel the slowliness of Excel. I have seen something like this using the code (VBA) and it was not so slow compare with the formula created on the cell.
Reset VBA Code
When I execute a macro, and if during the macro execution I press the "Esc" key, the execution stops and I get a Microsoft Visual Basic window with the message that code execution has been interrupted with buttons to Continue, End, Debug and Help. If I click the "End" button, the window closes and Excel is at rest - which seems to be some sort of Reset process.
I have a need to execute that process while Excel is at rest.
Is there any way to code the process in VBA?
Validation Code Vba
I want to validate the length of data is inserted into the cell as integers only, so im wanting it to be 16 digits long (no shorted or longer). I've already managed to make sure that only numbers can be used using the code below :
ElseIf Not IsTextAllNumeric(Range("H23")) Then
MsgBox "Card number must be digits only" & vbCrLf & _
"Please re-enter the card number", vbOKOnly + vbCritical, "Data Error"
Now im not 100% sure on how to make sure that the length is a certain amount of digits. I've babbled on for a bit on a not so complicated question.
To Execute VBA Code @ 9:30:01 Exactly
Using Excel 2003 with WinXP. I'm trying to run macro code automatically whenever time = 9:30:01 (or whatever time I pick) for a stock market trading program, which is why the exact time matters so much. I've been able to get the time to update fine, but unless I click on the worksheet while the time condition is TRUE then my code doesn't run. The time actually is sent to me from the stock data provider and it shows up in a cell as a constantly updating value.
I've tried using the Workbook_SheetChange function and OnTime method, but without luck.
In both cases, unless I activate the sheet the code doesn't run. By activate, I mean that I have to click on the sheet when the values that trigger the code to run would be true. If I do that it works just fine, but sitting around and clicking on a worksheet defeats the purpose of automation. Since I'm trading stocks this has to be very exact, so I can't trust a macro scheduler to do this.
The code further below is what I'm trying to get to run. The time value is in cell L1. In cell L2 I have the following
VBA Code Stops
My code below works great all the way to the end. When the last message box comes up, If the user chooses Yes. I want them to be directed to the sheet "C123". But currently it just stays on the sheet that I named "Home".
What am I missing here?
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Log")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
'check for a Reason Code
If Trim(Me.ComboBox2.Value) = "" Then
MsgBox "Please enter a reason code and ensure that date is correct!"
Speeding Up Vba Code
I've been working on cleaning up some code that copies particular information from one sheet (as the original must remain unedited) and then edits out irrelivant information.
However I've noticed that my "before" code moves far faster than my "after" code, which is odd considering that I've cleaned out a lot of excess code and the end results are the same.
I attach an example of my old fast code and my new slow code - can anyone advise where I have gone wrong ? Run the fast code first and then the slow one - you'll see the difference!
VBA Code And Macros
I'm trying to teach myself VBA code and macros, and I can't work out where the code should go. Do I double click on the worksheet, and put the macro code there, or do I have to create a 'module' and put the code there? I have tried to find online tutorials but I really need a 'for idiots' guide.
Licence A Vba Code?
I am developing a spreadsheet that I am hoping to sell. It has a high probability of being copied by others, so I would like to somehow put a licence in the sheet. Has anyone had and success with doing this? I was thinking about generating some HEX number that includes the user name. I would give them the code and they paste it in a sheet with their name to unlock the sheet. Trouble is that they can copy the name and the code. Is there a way to find some unique ID on the PC itself? I want to license machines, not people.
Using Labels In VBA Code
In the following VBA Code. I have a section labeled tier2 and a section labeled tier3, as you can see.
Both of the calculation formulas are refering to the items listed.
Will the code in the Tier3 section ever refer to the values in the tier 2 section, since they have the same label names?
VBA-code Not Working
I have the next VBA-
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("E:N")) Is Nothing Then
If Range("E34").Value = 0 Then
Application.EnableEvents = False
Range("G8").Value = Range("G8").Value + 1
If Range("J34").Value = 0 Then
Application.EnableEvents = False
Range("G9").Value = Range("G9").Value + 1
Application.EnableEvents = True
The code don't work. What's wrong with it?
VBA Code Optimization
Can anyone recommend a good source for tips on optimizing VBA code? I'm working on
an application that reads and interprets large text files (3500 lines) and starting to think
about the efficiency of the code inside my read loop.
For example I'm wondering how Excel actually implements access to cells internally. Is a
cell just a variable or part of an array?
If I do something like: range("A1").value = range("A1").value + 1 inside a loop is there a
performance penalty compared with saying: count = count + 1 and then writing this to a
cell outside the loop, eg: range("A1").value = count ?
Modifying VBA Code
This code works great for me, but I need some help modifying it. This code searches for data in the whole sheet, two things I would like to do is limit the search range to one column and then to find the whole string, not partials, for example, find 331 without finding all the 33's or 31's.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRange As Range
If Target.Address = "$A$1" Then
Set MyRange = Cells.Find(what:=Target.Value, After:=Target)
If Not MyRange Is Nothing Then MyRange.Select
Add If To This VBA Code
I need to add an IF condititon.
If cell is empty then leave it empty.
'Erik Van Geit
Dim SC As Integer 'Source Column
Dim TC As Integer 'Target Column
Dim FR As Long 'First Row
Dim LR As Long 'Last Row
Dim RN As Long 'Row Number
FR = 13
SC = 10 '26 = column "Z"
TC = 10
LR = Cells(Rows.Count, SC).End(xlUp).Row