Autoprint worksheet

anthony 1224

New Member
Joined
Apr 28, 2015
Messages
12
Greetings Forum,
Win 8
Excel 2010

I am working with a simple workbook that contains a ledger worksheet and individual worksheets linked to the ledger. I am trying to find out how to create a macro that will automatically print and individual worksheet if a specific cell on the ledger is changed. For example if I enter an amount on ledger B2 which is the ledger entry spot for Customer 1 then I would like the worksheet named "Customer 1" to print.
Thank you for the opportunity to post my question.
Anthony
 
Hi Joe the cell is labeled 1001 no quotations and the tab is labeled 1001 no quotations. I ran the code on the ledger worksheet there are no other macros running it gave a compile error in the vicinty of sheets(target.offset.....
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi Joe the cell is labeled 1001 no quotations and the tab is labeled 1001 no quotations. I ran the code on the ledger worksheet there are no other macros running it gave a compile error in the vicinty of sheets(target.offset.....
Are you running the code with the ledger sheet active? Can you tell me exactly what the error message says and what line is highlighted when the error occurs? I've tested the code and it works fine for me so I really need the details to have any hope of diagnosing your problem.
 
Upvote 0
yes sir this is the line highlighted Sheets(Target.Offset(0, -1)).PrintOut the instruction is to change the worksheet name to suit but I dont know what or where to change
Thanks
Anthony
 
Upvote 0
yes sir this is the line highlighted Sheets(Target.Offset(0, -1)).PrintOut the instruction is to change the worksheet name to suit but I dont know what or where to change
Thanks
Anthony
That comment line is a carryover from my original post and is no longer relevant, but no matter, now I understand your problem. It's not a compile error, it's that your tab name is 1001 not "1001". This should fix it. Remove the old code and copy/paste this in its place.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Set Target = Target(1)
If IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row)) Is Nothing Then
    Sheets(CStr(Target.Offset(0, -1))).PrintOut
End If
End Sub
 
Upvote 0
Thank you sir, do I paste this code on the ledger worksheet or on the actual worksheet?
Thanks again
Tony
Its for the ledger worksheet. Go back to post #2 and follow the instructions there. When tthe VBE window opens, remove any code that's there from prior posts and then paste the revised code in its place. Then change a cell in col B of the ledger sheet to test if the correct worksheet prints.
 
Upvote 0
Hi Joe,
This is working thank you for all of your help. If I were to add columns in the future which would shift the current column B to E would I just change the range in the code from B2 to E2?
Thanks again and I appreciate your efforts!
Anthony
 
Upvote 0
Hi Joe,
This is working thank you for all of your help. If I were to add columns in the future which would shift the current column B to E would I just change the range in the code from B2 to E2?
Thanks again and I appreciate your efforts!
Anthony
You are welcome.

If you add columns in front of col A then change B to E in this line:
Rich (BB code):
If Not Intersect(Target, Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row)) Is Nothing Then
If you add columns in front of col B then ALSO change the -1 to -4 in this line:
Rich (BB code):
Sheets(CStr(Target.Offset(0, -1))).PrintOut
 
Upvote 0
how could I force this code to print to a specific printer we have several that are used and one specifically for this ledger which is not typically the default.
Thanks
Anthony
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,549
Members
449,170
Latest member
Gkiller

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top