problem for copynig from one sheet to another sheet and print it automatically

nimavao

New Member
Joined
Dec 3, 2016
Messages
3

i have problem that i think it is not easy to solve(
maybe not,but i think it is so hard :wink: ) ,i have a 2sheet(shhet9 and sheet10) and a user form,i put command button on userform for printing the special area of sheet10,data should copy from sheet 9 to sheet 10 by step 1row by 1row then print the area of sheet10 and copy next row and continue this proces until last row in sheet9.
i find way for do it but it is just work for some steps(i mean that i should right code for it each time),if anyboady can pleas help me for make it by excell
and this is my code :

Private Sub CommandButton11_Click()
Sheet9.Activate
If Sheet9.Range("A2").Value = "" Then
MsgBox "you did not press the insert data button"
Sheet9.Activate
Range("A:A").Select
Selection.ClearContents
Exit Sub
Else
Sheet10.Range("I1").Value = Sheet9.Range("A2")
End If
Sheet10.Activate
Range("A4:M78").Select
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 1
End With


ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,1,,,TRUE,,FALSE)"
Application.Wait (Now + TimeValue("0:00:1"))
If Sheet9.Range("A3").Value = "" Then
MsgBox "printing done"
Exit Sub
Else
Sheet10.Range("I1").Value = Sheet9.Range("A3")
End If
Sheet10.Activate
Range("A4:M78").Select
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,1,,,TRUE,,FALSE)"
Application.Wait (Now + TimeValue("0:00:1"))
If Sheet9.Range("A4").Value = "" Then
MsgBox "you did not press the insert data button"
Exit Sub
Else
Sheet10.Range("I1").Value = Sheet9.Range("A4")
End If
Sheet10.Activate
Range("A4:M78").Select
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,1,,,TRUE,,FALSE)"
Application.Wait (Now + TimeValue("0:00:1"))
If Sheet9.Range("A5").Value = "" Then
MsgBox "printing done"
Exit Sub
.
.
.
.
.
continue....
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
is this what you want?

Code:
Private Sub CommandButton1_Click()
Dim sh1 As Worksheet, sh2 As Worksheet, rng As Range, c As Range
Set sh1 = Sheets("Sheet9")
Set sh2 = Sheets("Sheet10")
Set rng = sh1.Range("A2", sh1.Cells(Rows.Count, 1).End(xlUp))
    For Each c In rng
        If c.Value = "" Then
            MsgBox "You did not press the insert button"
            sh1.Range("A:A").ClearContents
        Else
            sh2.Range("I1") = c.Value
                With sh2.PageSetup
                    .FitToPagesWide = 1
                    .FitToPagesTall = 1
                End With
                ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,1,,,TRUE,,FALSE)"
                Application.Wait (Now + TimeValue("0:00:1"))
        End If
    Next
MsgBox "Printing Done"
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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