VBA Print sheets with differing values from second sheet

Mark1963

New Member
Joined
Dec 2, 2024
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi
Hopefully someone can help me?
I have two sheets called 'Form' and 'Data'. I want to print multiple copies of the sheet called form with different values selected from the sheet 'Data' The range of the data is in columns A B and C. I need to post and print the the values in the cells D2, D3 and D4
As you can see the code should loop through the rows and put the values in the column on the sheet called Form.
Unfortunately it Loops through column A and changes that value but not column B or C
I assume its something obvious I've missed?

Thanks in advance

Mark
 

Attachments

  • VBA Code.png
    VBA Code.png
    28.6 KB · Views: 3

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Editable version of the code is below

VBA Code:
Sub Button3_Click()

Dim rep As Range
Dim Code As Variant
Dim Branch As Variant
Dim wsTarget As Worksheet
Dim wsSource As Worksheet

 
 'set up the target worksheet
  Set wsTarget = Sheets("Form")
 

'set the source worksheet
    Set wsSource = Sheets("Data")
      
For Each rep In Range("A2", Range("A" & Rows.Count).End(xlUp))
    
     Code = Range("B2:B9")
     Branch = Range("C2:C9")
          
    
    ThisWorkbook.Sheets("Form").Range("D2").Value = rep.Value
    ThisWorkbook.Sheets("Form").Range("D2").Font.Bold = True
    
    ThisWorkbook.Sheets("Form").Range("D3").Value = Code
    ThisWorkbook.Sheets("Form").Range("D4").Value = Branch
  
    With wsTarget.PageSetup
    End With
    wsTarget.PrintPreview
    
    Next

  
 
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

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