Home |
Search |
Today's Posts |
#5
![]() |
|||
|
|||
![]()
Dave,
I'm attempting to use your code to quickly print data in my form template, however, some of my rows do not contain data, for example: I have a section for 2 buyers but in most deals there is only 1 buyer and an amount, so my section for my second buyer is left blank. When running your code, I keep getting a ***run-time error '1004', Method 'Range' of object'_Worksheet' failed*** on this string: FormWks.Range(myAddresses(iCtr)).Value _ = myCell.Offset(0, iCtr).Value I'm not sure what to do at this point. Here is my VBA code I am using: Option Explicit ' Developed by Contextures Inc. ' www.contextures.com Option Base 0 Sub PrintUsingDatabase() Dim FormWks As Worksheet Dim DataWks As Worksheet Dim myRng As Range Dim myCell As Range Dim iCtr As Long Dim myAddresses As Variant Dim lOrders As Long Set FormWks = Worksheets("Printout") Set DataWks = Worksheets("Active") myAddresses = Array("C4", "C5", "C7", "C9", "", "C10", "C11", "C12", "C14", "", "C15", "C16", "C17", "C39", "C19", "C20", "C21", "C23", "C24", "C25") With DataWks 'first row of data to last row of data in column B Set myRng = .Range("B4", .Cells(.Rows.Count, "B").End(xlUp)) End With For Each myCell In myRng.Cells With myCell If IsEmpty(.Offset(0, -1)) Then 'if the row is not marked, do nothing Else .Offset(0, -1).ClearContents 'clear mark for the next time For iCtr = LBound(myAddresses) To UBound(myAddresses) FormWks.Range(myAddresses(iCtr)).Value _ = myCell.Offset(0, iCtr).Value Next iCtr Application.Calculate 'just in case 'after testing, change to Preview to False to Print FormWks.PrintOut Preview:=True lOrders = lOrders + 1 End If End With Next myCell MsgBox lOrders & " Records were printed." End Sub Any and all help is greatly appreciated!!! Thanks, Josh |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
List and subtotal selected items, then print separate item list | Excel Worksheet Functions | |||
Print Pivottable - show all selected items in page filter | Excel Discussion (Misc queries) | |||
How to print only selected areas from an order sheet I created. | Excel Discussion (Misc queries) | |||
order form with multiple items and sizes for items | Excel Discussion (Misc queries) | |||
named range, data validation: list non-selected items, and new added items | Excel Discussion (Misc queries) |