Macro/VBA suggestion needed

Flora2021

New Member
Joined
Apr 28, 2022
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a spreadsheet (sheet1)that we need to print for approximately 90 employees. On this sheet there is a name, 3 different department fields, and a date range field.
I have another sheet (Sheet2) that lists all of this data in separate columns. I would like to be able to copy and paste each of the columns into the fields on sheet one and then print and repeat. I know I can create a macro to do this function, but I don't want to repeat it each time for 90 people. Is there a way to make it look at next row and repeat the steps?
 

Attachments

  • TR1.PNG
    TR1.PNG
    8 KB · Views: 7
  • TR2.PNG
    TR2.PNG
    16.3 KB · Views: 8

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
this should work for you


Sub fill_and_print()
i = 2
Do Until Sheet2.Cells(i, 1) = ""
For j = 1 To 5
If Sheet2.Cells(i, j) = "" Then Sheet1.Cells(j, 2) = "" Else Sheet1.Cells(j, 2) = Sheets.Cells(i, j)
Next

Sheet1.PrintOut
i=i+1

Loop
End Sub
 
Upvote 0
This is the macro I created that works, but only for the one record :(

Sub Training_Records()
'
' Training_Records Macro
'
' Keyboard Shortcut: Ctrl+Shift+T
'
Sheets("Sheet2").Select
Range("A2").Select
Selection.Copy
Sheets("Sheet1").Select
Range("B2:D2").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Range("B2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("B3:D3").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Range("C2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("B4:D4").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Range("D2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("B5:D5").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Range("E2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("C6:D6").Select
ActiveSheet.Paste
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End Sub
 
Upvote 0
woops sorry, there was a 2 missing (also make sure you have the i=i+1 line before the loop)

Sub fill_and_print()
i = 2
Do Until Sheet2.Cells(i, 1) = ""
For j = 1 To 5
If Sheet2.Cells(i, j) = "" Then Sheet1.Cells(j, 2) = "" Else Sheet1.Cells(j, 2) = Sheets2.Cells(i, j)
Next

Sheet1.PrintOut
i=i+1

Loop
End Sub
 
Upvote 0
this is what I get for not fully testing because I didn't want to print....


Code:
Sub fill_and_print()
i = 2
Do Until Sheet2.Cells(i, 1) = ""
For j = 1 To 5
If Sheet2.Cells(i, j) = "" Then Sheet1.Cells(j, 2) = "" Else Sheet1.Cells(j, 2) = Sheet2.Cells(i, j)
Next

Sheet1.PrintOut
i = i + 1

Loop
End Sub
 
Upvote 0
Hi, Its very close LOL
the first record works perfect but the other records are skipping the Name, and double posting the training period and placing the depts in wrong fields.
 
Upvote 0
alright one last shot... I didn't notice the blank row 1, and the training records being put in column C...if this doesn't work I give up

Code:
Sub fill_and_print()
i = 2
Do Until Sheet2.Cells(i, 1) = ""
For j = 1 To 4
    If Sheet2.Cells(i, j) = "" Then Sheet1.Cells(j + 1, 2) = "" Else Sheet1.Cells(j + 1, 2) = Sheet2.Cells(i, j)
Next
If Sheet2.Cells(i, j) = "" Then Sheet1.Cells(j + 1, 3) = "" Else Sheet1.Cells(j + 1, 3) = Sheet2.Cells(i, j)
Sheet1.PrintOut
i = i + 1

    Loop
End Sub
 
Upvote 0
Just a slight modification to @Puertorekinsam's Post #7 should get you there:

VBA Code:
Sub fill_and_print()
    Dim i As Long, j As Long
    i = 2
    Do Until Sheet2.Cells(i, 1) = ""
        For j = 1 To 5
            Sheet1.Cells(j + 1, 2) = Sheet2.Cells(i, j)
        Next
        
        Sheet1.PrintOut
        i = i + 1
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,786
Members
449,125
Latest member
shreyash11

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