Print from database

Charlreena

New Member
Joined
Jul 17, 2018
Messages
3
Hi,

I have a vba code within my worksheet already which allows me to pull a row of data from a database into an order form (on a separate sheet) and print (I can also pull multiple lines at once & it will print each one for me).

However I now need to be able to replicate this onto another sheet at the same time . The data being pulled is the exact same array - just needs to go into another sheet as well as the first one within the same code.

I had a lot of help on this code to begin with, so struggling to know now how to amend it to fit this in, or if it's possible.

This is my code currently

Code:
Option Base 0

Sub ConfirmOrder2()
Dim FormWks As Worksheet
Dim DataWks As Worksheet
Dim myRng As Range
Dim myCell As Range
Dim iCtr As Long
Dim myAddr As Variant
Dim lOrders As Long

Application.ScreenUpdating = False
Sheets("Order Form").Visible = True

Set FormWks = Sheets("Order Form")
Set DataWks = Sheets("Quote Database")

myAddr = Array("G9", "G10", "G11", "G12", "C14", "C15", "C16", "C17", "C18", "C19", "C20", "C21", "B25", "C25", "D25", "E25", "F25", "G25", "H25", "I25", "H38", "I38", "B26", "C26", "D26", "E26", "F26", "G26", "H26", "I26", "H39", "I39", "B27", "C27", "D27", "E27", "F27", "G27", "H27", "I27", "H40", "I40", "B28", "C28", "D28", "E28", "F28", "G28", "H28", "I28", "H41", "I41", "B29", "C29", "D29", "E29", "F29", "G29", "H29", "I29", "H42", "I42", "I30", "H31", "H32", "H33", "H43", "I43", "H44", "H45", "H46")

With DataWks
  Set myRng = .Range("B3", _
    .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In myRng.Cells
  With myCell
    If IsEmpty(.Offset(0, -1)) Then

    Else

      .Offset(0, -1).ClearContents
      For iCtr = LBound(myAddr) _
        To UBound(myAddr)
        FormWks.Range(myAddr(iCtr)).Value _
          = myCell.Offset(0, iCtr).Value
      Next iCtr
      Application.Calculate
      FormWks.PrintOut Preview:=False
      lOrders = lOrders + 1
    End If
  End With
Next myCell

MsgBox lOrders & " orders were printed."

    Sheets("Order Form").Visible = False
    Application.ScreenUpdating = True

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,092
Messages
6,123,063
Members
449,090
Latest member
fragment

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