VBA print loop, cycle a range through a cell and print out

dgarrod

New Member
Joined
May 18, 2016
Messages
11
I have a "Build Sheet" tab in my workbook, this enables us to make prints of all the details needed for each line item.

TLDR: Can you help me write a macro to call a range/array 'Build Sheet'!AF5:AF254 or from name managed "BSPrint". Into a macro that then loops to print the "Build Sheet" for each line in this "BSPrint" via cycling this range through the value in J5 of this "Build Sheet" worksheet.

Details:
I have a program that I inherited at my company. We use this program to separate, parse, and determine the details needed for a certain option available on all our orders. This option gets configured by the customer for their individual needs (custom) and this then is used to formulate the sheet details for each line item for MFG needs on factory floor. All these details are displayed on a single sheet in our program. These "Build Sheet" have a drop down input for cycling through the line items on the order. In an attempt to print this automatically, not have to manually click change each line item and then click print, I have parsed out the order line items and removed all blanks where applicable to enable me to use a VBA macro to call the range/array of printable line items. In this tab we cycle our orders through by line item. I want to use this setup with the range/array to print only the needed orders details (eg. line item 2, 4, 5, 10, 15, 20).

My attempt:
Dim vars As Range, i As Long
vars = ThisWorkbook.Worksheets("Build Sheet").Range("AF5:AF254")
For i = LBound(vars) To UBound(vars)
[J5] = vars(i)
Worksheet.PrintOut
Next i
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Bumping for anyone looking for a challenge.

Excel guru's, is this type of request not possible and if you believe so can you tell me why?
 
Upvote 0
Bump, please anyone have any type of advice or places to point me to determine how to help myself?

I've been at this problem for months on and off because I can't find a way to call a workcell range into a vba code.
 
Upvote 0
You appear to be mixing range and array.
Try either
Code:
Dim vars As Range, cel As Range
Set vars = ThisWorkbook.Worksheets("Build Sheet").Range("AF5:AF254")
For Each cel In vars
    [j5] = cel.Value
    Worksheet.PrintOut
Next cel
or
Code:
Dim vars As Variant, i As Long
vars = ThisWorkbook.Worksheets("Build Sheet").Range("AF5:AF254").Value
For i = LBound(vars) To UBound(vars)
    [j5] = vars(i)
    Worksheet.PrintOut
Next i
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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