Please help to finalize a code...

BELFRED6

Board Regular
Joined
Oct 31, 2008
Messages
110
Hello, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
In order to print invoices based on the result of a dropdown list, I am using the following code that Jon von Der Heyden helped me build. Thousands of thanks to him!<o:p></o:p>
<o:p> </o:p>
Sub Print_Invoice()

Dim rCell As Range

With ActiveSheet 'change to relevant sheet name if you want to execute macro from another sheet

For Each rCell In .Range("A2:A10")
.Range("J3").Value = rCell.Value: Calculate
If .Range("P14").Value > 0 Then .PrintOut
Next rCell
End With

End Sub <o:p></o:p>
<o:p> </o:p>
<!-- / message --><!-- sig -->You can see all details of that previous post at http://www.mrexcel.com/forum/showthread.php?t=376244&highlight=printing <o:p></o:p>
<o:p> </o:p>
I am trying to include in that code two more parameters:<o:p></o:p>
1/ Each invoice needs to be printed TWICE.
2/ I would like to print out invoices in an ALPHABETICAL order provided by the content of cell H3 (name of the deliverer). In H3, I have a vlookup function changing the name of the deliverer based on the selected client from the dropdown list located in J3.
Any idea how to do that?

Your help would be very valuable. <o:p></o:p>

<!-- / message -->
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
for the printout try

Then .PrintOut Copies:=2

For the alphabetical. You´d need to sort your range first, but not sure how the range looks?
 
Upvote 0
Thanks but now I don't get it.

I added what you suggested but now the macro no longer works and returns a syntax error.
Sub Print_Invoice() is yellow highlighted
For Each rCell In .Range("A2:A10") appears in red letters.

I am totally confused...
 
Upvote 0
Hi

Did you change it to look like this?
I tried it and it tries to print 2 copies.

Code:
Sub Print_Invoice()

Dim rCell As Range

With ActiveSheet 'change to relevant sheet name if you want to execute macro from another sheet

For Each rCell In .Range("A2:A10")
.Range("J3").Value = rCell.Value: Calculate
If .Range("P14").Value > 0 Then .PrintOut Copies:=2
Next rCell
End With

End Sub
 
Upvote 0
Thank you so much for your help. I copied and pasted the whole code again and now it did work. That's great.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
So now that my printing problem is solved, how can I set an ALPHABETICAL PRINTING ORDER? I would like to have the macro print out all invoices delivered by Driver AAA first, then all invoices delivered by driver BBB, and so on...
<o:p></o:p>
In cell H3 of the invoice form, appears the name of the deliverer. This name changes depending on the client's name returned by the dropdown list located in J3.<o:p></o:p>
I hope I am clear enough so you can guide me here. Thanks a lot for your advice!<o:p></o:p>
<o:p> </o:p>
 
Upvote 0
i´m afraid that will only work with this loop if you´ve managed to sort the invoices to deliverer before the loop starts.

So we´d need to look at how to achieve that, and for that you need to post an example table of how this looks. :)
 
Upvote 0
Before I started using VLOOKUP functions and a dropdown list, I had one worksheet for each store (each worksheet had the invoice form for that specific store).
I then used a code for the alphabetical order printing. It is part of the code below. That code was designed to print out each worksheet if the value of cell J1>0 and it printed out the number of copies mentioned in cell L1. The sorting issue was solved by the last part of the code but it does not mean anything to me…
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> Is it possible to use the last part of the code below in the new code provided by Shyrath? </o:p>
<o:p> </o:p>
Sub test()<o:p></o:p>
Dim i As Long, a(), n As Long<o:p></o:p>
ReDim a(1 To Sheets.Count, 1 To 2)<o:p></o:p>
For i = Worksheets("ТОРТЫ").Index + 1 To Worksheets.Count<o:p></o:p>
With Worksheets(i)<o:p></o:p>
If .Range("J1").Value <> "" Then<o:p></o:p>
n = n + 1<o:p></o:p>
a(n, 1) = .Name<o:p></o:p>
a(n, 2) = .Range("J1").Value<o:p></o:p>
End If<o:p></o:p>
End With<o:p></o:p>
Next<o:p></o:p>
VSortMA a, 1, n, 2<o:p></o:p>
For i = 1 To n<o:p></o:p>
With Sheets(a(i, 1))<o:p></o:p>
.printout Copies:=.Range("L1").Value<o:p></o:p>
End With<o:p></o:p>
Next<o:p></o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
Private Sub VSortMA(ary, LB, UB, ref)<o:p></o:p>
Dim M As Variant, i As Long, ii As Long, iii As Long<o:p></o:p>
i = UB: ii = LB<o:p></o:p>
M = ary(Int((LB + UB) / 2), ref)<o:p></o:p>
Do While ii <= i<o:p></o:p>
Do While ary(ii, ref) < M<o:p></o:p>
ii = ii + 1<o:p></o:p>
<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:eek:ffice:smarttags" /><st1:place>Loop</st1:place><o:p></o:p>
Do While ary(i, ref) > M<o:p></o:p>
i = i - 1<o:p></o:p>
<st1:place>Loop</st1:place><o:p></o:p>
If ii <= i Then<o:p></o:p>
For iii = LBound(ary, 2) To UBound(ary, 2)<o:p></o:p>
temp = ary(ii, iii): ary(ii, iii) = ary(i, iii): ary(i, iii) = temp<o:p></o:p>
Next<o:p></o:p>
ii = ii + 1: i = i - 1<o:p></o:p>
End If<o:p></o:p>
<st1:place>Loop</st1:place><o:p></o:p>
If LB < i Then VSortMA ary, LB, i, ref<o:p></o:p>
If ii < UB Then VSortMA ary, ii, UB, ref<o:p></o:p>
End Sub<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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