VBA Updated Template from table then print

Finalion

New Member
Joined
May 2, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am trying to get the Order#(Cell A5) updated from the Pivot Table "Piv" in Column K. then Print two copies and continue doing so for every Order # present in the table.
-All of the other fields populate based off of the Order #.

I record a macro(In Green Below) to see what VBA would populate but I am having a hard time figuring out how to get VBA to look at the table and run no matter if there is 5 sets of data in the table or 50.
I am getting lost on how to get VBA to look at the cell's the "Piv" table is occupying and print dynamically based on the table.

Or would it be simpler to something like below in an "IF" function?
How could I tell VBA to keep going until is runs out of data without manually putting in all of the ranges?

Range("K3").Copy Range("A5")
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True, IgnorePrintAreas:=False
Range("K4").Copy Range("A5")
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True, IgnorePrintAreas:=False
Range("K5").Copy Range("A5")


Any help or a push in the right direction would be greatly appreciated.

Sub Macro4()
'
' Macro4 Macro
'
ActiveSheet.PivotTables("Piv").PivotSelect "'45812'", xlDataAndLabel _
+ xlFirstRow, True
Selection.Copy
Range("A5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True, _
IgnorePrintAreas:=False
ActiveSheet.PivotTables("Piv").PivotSelect "'46017'", xlDataAndLabel _
+ xlFirstRow, True
Selection.Copy
Range("A5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True, _
IgnorePrintAreas:=False
End Sub


1651522421867.png
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
VBA Code:
Sub Print_all()
Application.ScreenUpdating = False

lr = Cells(Rows.Count, "K").End(xlUp).Row

x = Application.Dialogs(xlDialogPrinterSetup).Show
If x = False Then Exit Sub

For r = 3 To lr
[A5] = rs.Cells(r, "K")
ActiveWindow.SelectedSheets.PrintOut copies:=2
Next r

Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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