[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBA Code - Loops, Counters, & Stops

Posted on 2013-06-12
2
Medium Priority
?
347 Views
Last Modified: 2013-06-12
Hello Experts,

Please bare with me as I explain this,...

I am looking for a VBA code that involves loops & counters (or at least I think that's what is needed).

Things you'll need to know...

Worksheets:  Input / Preview

Named Cells:  TotalPallets / PrintSelection

Excisting Print Code:  

Sub Pallet_Tag_Print()
ThisWorkbook.Worksheets("Preview").PrintOut
End Sub

Open in new window


See attached file...

As you can see, there are "4" total pallets. Along with the units & weights of each pallet listed to the right.

If you click on the Preview worksheet, you'll see it reflects information of Pallet # 1.

If you change the "Print Pallet Tag" field from 1, to 2 - then click on Preview - you'll see the Preview worksheet now reflects information about Pallet # 2.

So basically, there is ONE preview page - that is dynamic, and the user controls what page they are previewing by adjusting the "Print Pallet Tag" #.

Currently, when the user wants to print the pallet tags they have to put 1 into the field, then hit the print button, then they put 2 in the field, then print, and so on...

Obviously after a while, this is annoying.  Ideally, I would like a print all option.  But in order for it to work correctly - the VBA code will need to change the number in the "Print Pallet Tag" field.

Assuming I havn't lost you,...  Here is what I would like...

Step 1:  Code looks to named cell "PrintSelection".
Step 2:  IF value equals a #, then execute this line of code:

ThisWorkbook.Worksheets("Preview").PrintOut

Open in new window


Step 3:  After that code executed, code ends.

Step 4:  IF value of "PrintSelection" equals nothing, then assume Print All.
Step 5:  Code looks at named cell "TotalPallets".
Step 6:  The value in TotalPallets, would represent the # to stop on.
Step 7:  Code puts a "1" into PrintSelection, then runs the print code
Step 8:  Code puts a "2" into PrintSelection, then runs the print code.
Step 9:  Code puts a "3" into PrintSelection, then runs the print code.

It repeats those steps, until it reaches the TotalPallets number then stops.

I HOPE this made sense.  if you have any questions - please let me know.

Thank you in advance!

~ Geekamo
Pallet-Tag-Generator--Must-Enabl.xlsm
0
Comment
Question by:Geekamo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
agillanders earned 2000 total points
ID: 39242982
Try the attached. I added two small macros to Module 6.

Pallet_Tag_PrintSelector - decides which type of print (all or one) is required
Pallet_Tag_PrintAll - which prints all pallet tags from 1 to TotalPallets

Regards

Alistair
PalletTag-Test.xlsm
0
 
LVL 1

Author Comment

by:Geekamo
ID: 39243240
@ Alistair,

I don't have access to a printer while testing this at home.  In order to test this, I placed a " ' " before the two lines of print code to disable them.  Then I added a MsgBox right above them, so that way I can see the code step through all the loops.

It has worked beautifully!  I really appreciate the time you spent on this.  Thank you so much!

~ Geekamo
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question